There are a number of ways that webMathematica 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.
When an error is generated webMathematica deals with it in one of two ways. For serious errors that require the Mathematica kernel to be restarted, the request results in an HTTP error of status 403, indicating that the server could not complete the request. Alternatively, other errors result in a Mathematica exception being thrown and this leads to a normal page being returned, but with some special text being inserted for the error.
webMathematica 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|
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 webMathematica layout.