1

Is there any way I read exception from below method and pass it to other method for track. Response of catch block is different from exception.

Either adding some annotation or spring AOP or any other way.

public void function(){
  try{
    method();
  }
  catch(Exception e){
    return response;
  }
}
kriegaex
  • 63,017
  • 15
  • 111
  • 202
adit
  • 39
  • 3
  • Welcome to SO. Please learn what an [MCVE](https://stackoverflow.com/help/mcve) is and how to ask questions in a way enabling your peer developers to actually reproduce and analyse your problem instead of having to make educated guesses from tiny code snippets and ambiguous prose. Give your questions some more love, then you will get quicker and better answers, not the kinds of answers you got so far which do not really help you and just waste the time of the people writing the answers. I have an idea what you mean but I also have to guess. – kriegaex Sep 19 '19 at 04:19

2 Answers2

0

You can have a method with an exception parameter:

public void handleException(Exception e) {
    e.printStackTrace(); //for example print it   
}

Then you can pass your exceptions to this method:

try {
   //some code that can throw exception
} catch(Exception e) {
   handleException(e);
}
Gtomika
  • 845
  • 7
  • 24
0

I think what you want is to intercept an exception handler, not a thrown exception. For that you need to switch from Spring AOP to AspectJ mode as explained in the Spring manual.

For more details on the AspectJ handler() pointcut which does what you want, see my answers with code examples here:

The handler() pointcut is also described in the AspectJ documentation.

kriegaex
  • 63,017
  • 15
  • 111
  • 202