Hi,

I am developing a feature in WSO2 PC and in it I have a JavaScript front
end and a Java back end. To call java classes from the JavaScript I am
using Jaggery in between the above two. So my question is what is the best
practice in Exception handling and error logging in such a this scenario.

As I understand I can come out with few options.

Option 1- Catching the  exception in the Java class itself and log the
complete error with an appropriate custom error message using log.error(errMsg,
e), without throwing exceptions from the method signature, using throws
clause. (As we usually do in a sole java application). So here the
exceptions are completely handled from the back end and doesn't come at
least to the jaggery. And for the purpose of showing some error message to
the front end user we can return a message or flag or something from the
java function to the jaggery side. So at the jaggery side or even at the
javascript, we can check that return value and show the error message as an
alert and proceed depending conditionally on that return value.

Option 2- We can throw the the exception in the catch block of java class
using throw new ExceptionClassName("custom error message",e) and catch it
in the jaggery file. But here I am getting the problem that we cannot log
the complete long exception report using log.error(_ _) in jaggery. We can
just print the custom error message set by us when throwing it from Java
side. But I don't know is there any other way to trace that complete
exception in jaggery. Anybody know something on it?

Option 3- We can catch the error in the JavaScript, without catching in the
Jaggery. But I don't think this is ok as we won't be able to print the
exception in the server console if we do it so.

I want to know what is the best practice in such a this scenario and if it
is Option 2, what is the solution for the problem in it as mentioned there
above. Appreciate support from somebody.

Thanks,
Samitha

-- 
Samitha Chathuranga
Software Engineer, WSO2 Inc.
lean.enterprise.middleware
Mobile: +94715123761
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to