There are a number of ways that web*Mathematica* computations can lead to an error. An input might fail the security test, the computation might take too long so that the *Mathematica* kernel is restarted, or there might be some type of page logic error. You can learn about certain types of errors and, often, solve them using the logging system. However, it is not possible to avoid all errors, for example you cannot predict all inputs to the server, so some of them might fail the security test. In these cases you might want to customize the way the error is handled.

If you want to customize the handling of these errors, you can do this with *Mathematica* code to catch the *Mathematica* exceptions and by adding an error page to handle the HTTP error.

web*Mathematica* throws errors in *Mathematica* as MSPException expressions, and you can add code to catch these. The exceptions that can be caught are listed below.

MSPException["ParseError"] | if the value cannot be interpreted by Mathematica |

MSPException["SecurityError"] | if the value does not pass the security test |

MSPException["ValueError"] | if the value is not a string, this indicates a programmatic error by the page author |

MSPException["VariableError"] | if the variable is not a Mathematica symbol, this indicates a programmatic error by the page author |

MSPException["NoValueError"] | if a variable has no value |

MSPException["VersionError"] | if a version mismatch problem is found |

A sample implementation for errorFunction is shown below. As you can see, its signature gets two arguments; the actual exception expression is the second argument.

You can catch the HTTP errors by adding an error page. This can be done by adding code to the web.xml file that is found in the WEB-INF folder. The following should redirect to a page /Resources/Tools/Error.jsp; in fact, this is a sample page found in the web*Mathematica* layout.

<error-page>

<error-code>403</error-code>

<location>/Resources/Tools/Error.jsp</location>

</error-page>

Inside the error page you need to reset the error. You can also get an integral listing of the error and an error string. Sample code is shown in the following.

<%

response.setStatus(200);

Object type = (Object)request.getAttribute(

com.wolfram.msp.MSPStatics.MSPErrorType);

String text = (String)request.getAttribute(

com.wolfram.msp.MSPStatics.MSPErrorText);

%>