aspose file tools*
The moose likes Spring and the fly likes @AfterThrowing for unhandled exceptions? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "@AfterThrowing for unhandled exceptions?" Watch "@AfterThrowing for unhandled exceptions?" New topic
Author

@AfterThrowing for unhandled exceptions?

Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 614
Hi,

Tried @AfterThrowing in aspcet and what I understand is, its executed from the calling point as soon as there is exception but the exception still remains unhandled for example




now if getReport() is adviced by afterThrowing and it throws some exception then afterThrowing is invoked and then control goes to catch,is there a way we can handle the exception in AfterThrowing advice?

code for getReport throwing exception



code for @AfterThrowing




I know this can be achived by @Around advice by putting proceed method in try catch, but can same be done without it?

-Praful


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

No, In AfterThrowing, you cannot catch the exception, you can change the type of Exception or information in the Exception, but you still have to throw an exception through the Aspect.

Only in Around can you catch it and not re-throw one out.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 614
ah okay, but would have been nicer if it was possible to do so, yes Around seems to be one stop shop, nothing else really required...

thanks

-Praful
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Praful Thakare wrote:ah okay, but would have been nicer if it was possible to do so, yes Around seems to be one stop shop, nothing else really required...

thanks

-Praful


Actually, it wouldn't be nicer. Only Around makes the developer responsible for exceptions, calling the target and returning the object returned from the target. All four other advices don't put those requirements on the developer and makes it nicer and easier.

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @AfterThrowing for unhandled exceptions?