0

I think that all Error and Exception type extend from Exception class so how could i watch exception when the application stopped working because i want to run some logic when the exception thrown i am not just asking about try{} catch {} finally {}

if i want to make plugin to watch on any exception happen on application to run my logic

example if you have application named X and you have library named Y how could library Y watch and run logic when X throw Exception without edit on logic of X code

Ahmed Nasser
  • 114
  • 6

2 Answers2

1

Error and Exception classes are extended from Throwable class. Now If you want to catch exception, you can simply go with try-catch-(finally , If required) block. You must not catch Error, because error is something which you cannot recover, Below is the hierarchy, the Error and Exception are two different hierarchy except one thing that both are Throwable.enter image description here

pbajpai
  • 1,303
  • 1
  • 9
  • 24
  • i know this i asked about if you have application named x and you have library named Y how could library Y watch the X Exception without edit on logic of X application code – Ahmed Nasser Jun 17 '16 at 04:02
0

You can catch exception if you know the exception and execute your logic there. Or, you can write your logic in finally block after exception block. Eg:

try {
     ....
} catch (YourException e) {
    ....
} finally {
    // your logic
}
techtabu
  • 23,241
  • 3
  • 25
  • 34
  • i wan't to make it dynamically i wan't using reflection when the exception throw to run some logic without write login on finally – Ahmed Nasser Jun 17 '16 at 03:55