Hi Samitha, >From what I understand, you need to both print the full stack trace and throw a proper message to the front end.
If that so, you can catch the error, log it and throw a custom error from the java side. Cheers, Sachith On Wed, Mar 30, 2016 at 10:31 AM, Samitha Chathuranga <[email protected]> wrote: > 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 > [email protected] > http://wso2.org/cgi-bin/mailman/listinfo/dev > > -- Sachith Withana Software Engineer; WSO2 Inc.; http://wso2.com E-mail: sachith AT wso2.com M: +94715518127 Linked-In: <http://goog_416592669>https://lk.linkedin.com/in/sachithwithana
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
