Reputation: 1010
Try Catch from another method:
method1(){
try {
method2();
}catch(Exception e){
}
}
method2(){
try{
//ERROR FROM HERE
}catch(Exception e){
}
}
How will method1()
catch the error from method2()
?
Upvotes: 3
Views: 1426
Reputation: 25156
If you throw another exception in method2's catch block.
public void method2() {
try {
// ...
} catch(Exception e) {
throw new NullPointerException();
}
}
Upvotes: 2
Reputation: 1309
public void method1(){
try {
test2();
} catch (IOException ex) {
//catch test2() error
}
}
public void method2() throws IOException{
}
Use throws
Upvotes: 2
Reputation: 48837
It won't until you re-throw it within the catch
block of your method2
by adding throw e;
.
Upvotes: 0
Reputation: 4891
method1()
will not catch the error, unless you re-throw it from the catch
block in method2()
.
void method2() {
try {
// Error here
} catch(Exception e) {
throw e;
}
}
Upvotes: 9