This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)


allows you to control how exceptions thrown in Java are handled in Mathematica.
  • To use $JavaExceptionHandler, you first need to load J/Link using Needs["JLink`"].
  • The default behavior is for exceptions to appear as messages in Mathematica.
  • 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 3 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 Mathematica), 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.