Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@AfterThrowing for unhandled exceptions?

 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic