Announcement Announcement Module
Collapse
No announcement yet.
Spring AOP throws advice Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring AOP throws advice

    Query 1 :
    How to handle exception in afterThrowing(Exceptione) method of Spring AOP.
    I.e in try {} and catch {} block how the exception is caught in the catch block and then sent to the client in a well formed message. Also in console no exception is printed.

    I.e if i execute the following code without try and catch block
    int a=5;
    int b= a/0;

    then, a Arithematic Exception Divide By Zero is printed on the console.

    But if i surround the same above code by try and catch block, then the exception is caught and nothing is printed on the console.

    How can i acheive this using Spring AOP throws advice? how do i implement the afterThrowing(Exception e) method for this.

    Query 2:

    How can i propagate the Exception which i have received in afterThrowing(Exception e) method to the client side with well formed String message.
    I am actually using Weblogic Portal. So when an exception is occured in the business method how can i avoid that printing on the portlet user page.

    Need help on this.

  • #2
    I'm not sure you need to use AOP for something like this simple example...the reason that in the above example something gets printed is because it bubbles all the way to the top of your application and the message gets printed when the application exits. You could easily print the exception IN your catch block rather than just burying the exception.

    i.e. instead of doing this:

    Code:
    try
    {
        
    }
    catch(Exception e)
    {
        // do nothing
    }
    You can do this:

    Code:
    try
    {
       
    }
    catch(Exception e)
    {
        e.printStackTracke();
    }
    It's not very clear WHAT you want to do with the exception or HOW you want your application to behave after the exception.

    Comment


    • #3
      Spring AOP throws advice

      i actually dont want to use try {} catch block in my application, instead acheive the behaviour of try {} and catch block using throws advice.

      When a exception is thrown in my Portal application, it invokes the throwsAdvice() method,

      chudak : It's not very clear WHAT you want to do with the exception
      --> I want to handle the exception in this method to avoid it printing on the console.
      chudak : HOW you want your application to behave after the exception.
      --> I want to propogate this exception to the client side as a String message and display it on the portlet page instead of stack Trace getting printed by itself.

      Comment

      Working...
      X