Try Catch from another method:
method1(){ try { method2(); }catch(Exception e){ } } method2(){ try{ //ERROR FROM HERE }catch(Exception e){ } }
How to method1() catch the error from method2() ?
method1()
method2()
method1() will not catch the error if you haven't re-tossed it from block catch to method2() .
catch
void method2() { try { // Error here } catch(Exception e) { throw e; } }
If you have thrown another exception in the catch2 block of method2.
public void method2() { try { // ... } catch(Exception e) { throw new NullPointerException(); } }
public void method1(){ try { test2(); } catch (IOException ex) { //catch test2() error } } public void method2() throws IOException{ }
Use throws
This won't happen until you drop it into catch your block by method2 adding throw e; .
method2
throw e;