Custom Error Page c/w Cause and Stacktrace Information


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