allows you to control how exceptions thrown in Java are handled in the Wolfram System.


  • To use $JavaExceptionHandler, you first need to load J/Link using Needs["JLink`"].
  • The default behavior is for exceptions to appear as messages in the Wolfram System.
  • If you want to override this behavior (for example to temporarily silence messages from exceptions), assign a value to $JavaExceptionHandler.
  • The value of $JavaExceptionHandler is treated as a function that will be passed three arguments: the symbol associated with the message (this will currently always be the symbol Java), the message tag (this will be the string "excptn" for a typical exception or "pexcptn" for an exception generated by a manual return method where the exception occurs after the method has manually sent its result back to the Wolfram Language), and the descriptive string of text associated with the message.
  • You will typically set $JavaExceptionHandler within a Block so that its effect will be limited to a precisely defined segment of code, as in the following example that silences messages: Block[{$JavaExceptionHandler=Null&},obj@method[]].
  • You can use GetJavaException within your handler function to obtain the actual Java exception object that was thrown.

See Also

JavaThrow  GetJavaException