• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

@AfterThrowing for unhandled exceptions?

 
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic