Wednesday, April 3, 2013

Error Handling in Jaggery

Proper error handling is a key points in any application. If you are using WSO2 Jaggery, then you might have also come up with the same requirement.

Jaggery is JavaScript, hence try, catch and finally blocks can be used within your code as you usual. Also,  passed JavaScript Error object can be used to get a brief information about the error. But, as we are dealing with a server side environment, we might need to know additional details about the errors, such as stacktrace, line numbers etc.

Using the additional properties/methods which can be found in the passed Error object, error details can be accessed as below.
var log = new Log();

try {
    parse(null); //code where exception is thrown
} catch (e) {
    log.error(e.lineNumber); // Error occured line number
    log.error(e.fileName); // Error occured script name
    log.error(e.stack); // Executed JavaScript file stack
    log.error(e.message); // JavaScript error message

    log.error(e.rhinoException); // Rhino exception object
    log.error(e.javaException); // Java excepton object

    log.error(e); // Logs the stack trace

    print(e); // prints the stack trace
} finally {
    log.info('finally :)');
}


4 comments:

  1. Hi wageesha,
    Thanks for the informative post. Is there a better way to handle SOAP faults in jaggery?. Documentation says WSRequest object have a "error" member where it can handle SOAP faults. But I wasn't able to get it working.

    ReplyDelete
  2. Proper error handling is a key points in any application. If you are using WSO2 Jaggery, then you might have also come up with the same requirement. plain black salwar , black and yellow salwar suit ,

    ReplyDelete