Robert F Harwood commented on Jan 13, 2012

Re: Error Management in XPages

checked

Dominykas Kardokas commented on Sep 23, 2011

Re: Error Management in XPages

Great article, thanks Maire!

however looping through error ancestors using error.getCause() is far from straight forward.

I would like it to work something like this:

while(error instanceof java.lang.Throwable){

//check the exact type of error object and extract useful information

error = error.getCause();

}

it's not that simple though... for example caling getCause() on com.ibm.xsp.FacesExceptionEx object produces some kind of volatile object that will crash if you try to touch it [even with error != null]

com.ibm.jscript.InterpretException fails to call getCause() altogether. A little inconsistent if you ask me, but it can still be put to good use. What I have so far is:

var errObj = requestScope.error;

var goToNext = processError(errObj);

while(goToNext){

errObj = errObj.getCause();

goToNext = processError(errObj);

}

function processError(e){

var getNextCause = true;

print(e.toString());

if(e instanceof com.ibm.jscript.InterpretException){

print(e.getExpressionText());

print(e.getErrorLine());

getNextCause = false;

}

if(e instanceof com.ibm.xsp.FacesExceptionEx){

getNextCause = false;

}

if(e instanceof com.ibm.xsp.exception.EvaluationExceptionEx){

print(e.getErrorComponentId());

print(e.getErrorPropertyId());

}

return getNextCause;

}

in real life instead of the print() I am generating an email, then send it to sysadmin, while showing user general "something went wrong but we're on it" message

Ryan Buening commented on Jul 28, 2011

Re: Error Management in XPages

@Pablo - I'm trying to figure out how to do the same thing. Here is my error page so far: http://dl.dropbox.com/u/40159/xpErrorPage.txt

I have everything I want besides where the error happened at and the page name of the error. If anyone knows how to get either of these things on a custom error page please share!

Pablo Solano commented on Jul 27, 2011

Re: Error Management in XPages

I'm following the steps to show a custom Error page but It looks like the result of requestScope.error doesn't return the same value that returns e.toString() from try, catch.

For example:

try{

var doc:NotesDocument = database.getDocumentByUNID("none")

if (doc != null){

doc.appendItemValue("NewField", "Demo");

doc.save();

}

}catch(e){

print(e.toString());

context.redirectToPage("xErrorPage.xsp");

}

In this case e.toString() returns "Exception occurred calling method NotesDatabase.getDocumentByUNID(string)"

But, if I add the value requestScope.error to the Computed Field on XPage ErrorPage.xsp

It returns "com.ibm.xsp.exception.EvaluationExceptionEx: Error while executing JavaScript computed expression"

How can I show the error description and line where the error was generated?

I can't find any examples about getCause() or getError

I have tried:

var myerror:com.ibm.xsp.exception.EvaluationExceptionEx = requestScope.error;

//return myerror.getCause();

//return myerror.getMessage();

return myerror.getErrorText();

Bruce Lill commented on Aug 5, 2010

Error Management in XPages

It's due to the formating of the page:

var trace = requestScope.error.getStackTrace() ;

for( var i = 0; i < trace.length; i++){

stackTrace += trace[i] + '\n';

}

return stackTrace;

}]]>

Neemesh Patel commented on Oct 12, 2009

Stack seems to stop at a NotesException

Thanks for the article. It seems however if it encounters a NotesException it prematurely ends the stack trace for me. Anyone experience this?

For now I'll stick with the server default as that seems to show everything :)