Link to home
Start Free TrialLog in
Avatar of Tech Novice
Tech Novice

asked on

Can we break sequence of the throw in java.

Hi,

I need to create a common method which handles all the exception.There are controllers,logic layers,dao layers.
Flow is

isValidLogin() calls the method of logic layer validUserLogic() further goes to dao layer (validUserDAO) ,Now exception occurrred in the dao layer and the exception is thrown using (throw new AppBussinessException)

What i need is when exception is thrown from dao layer it should go to common classs which will take care of the exception.

How to achieve this?
Avatar of dpearson
dpearson

I think you have two choices (and neither may be practical in your situation):

Either you need a "top level handler" that catches all of these exceptions and explicitly passes them to the class that you wish to handle them

or

You can attach an "uncaught exception handler" to the thread and have that handle the exception.

Both require that you can set the correct exception handling (which exceptions are caught, which not) higher up the call stack.  Which may or may not be possible given your code base and how the DAO layer is called.

Doug
Avatar of Tech Novice

ASKER

Thanks for reply

You can attach an "uncaught exception handler" to the thread and have that handle the exception.
Can u please elaborate so that i can apply,somehow this looks feasible
ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am having web application in which i don't create threads,which are in built created by tomcat on each request, then how to handle in such scenario.
any clue?