Use the below code in a computed field on a separate Custom Control which will print the Stacktrace.
Please note that you need point your application to show this page if an error occurs.
<xp:text escape="true" id="computedField">
<xp:this.value>
<![CDATA[#{javascript:var stackTrace ="";
var trace = requestScope.error.getStackTrace() ;
for( var i = 0; i < trace.length; i++){
stackTrace += trace[i] + '\n';
}
return stackTrace;
}]]>
</xp:this.value>
</xp:text>
Check the link below which has detailed information about error handling in xpages: