Custom Error Page c/w Cause and Stacktrace Information

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="" xmlns:xsi=""
	xsi:schemaLocation=" xsdxp://localhost/xsp~core.xsd"
	pageTitle="${javascript:database.getTitle() + ' | Error'}">
		<xp:label style="font-weight:bold;font-size:12pt" value="An error has occurred:"></xp:label>
		<xp:text escape="true" id="computedField1">
					var output = requestScope.error.toString()+"\n\n";
					if(requestScope.error instanceof{
						var codeSnippet = requestScope.error.getErrorText(); 
						var control = requestScope.error.getErrorComponentId();
						var cause = requestScope.error.getCause();
						output += "In the control : " + control + "\n\n";
						if(cause instanceof{
							var errorLine = cause.getErrorLine();
							var errorColumn = cause.getErrorCol();
							output += "At line " + errorLine;
							output += ", column " + errorColumn + " of:\n";
							output += "In the script:\n";
						output += codeSnippet;
					return output;
		<xp:text escape="false" id="computedField" style="font-size:10pt">
				<![CDATA[#{javascript:var stackTrace = "";
					var trace = requestScope.error.getStackTrace();
					for(var i = 0; i < trace.length; i++){
						stackTrace += trace[i] + "<br/>";
					return stackTrace;

Use this snippet to create a custom error XPage.  Remember to set the Error Page in the Application Properties to point at your new custom error XPage.

If an exception occurs in your application, you'll see error output in the custom error page like this example:

An error has occurred: Error while executing JavaScript computed expression In the control : computedField7 At line 1, column 19 of: #{javascript:nonexistentObject.isDebugMode()}

Tony McGuckin
May 8, 2012 4:27 PM

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.

No comments yetLogin first to comment...