Try to catch another method
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()
?
+3
Christian eric paran
source
to share
4 answers
method1()
will not catch the error if you haven't re-tossed it from block catch
to method2()
.
void method2() {
try {
// Error here
} catch(Exception e) {
throw e;
}
}
+9
Alex DiCarlo
source
to share
If you have thrown another exception in the catch2 block of method2.
public void method2() {
try {
// ...
} catch(Exception e) {
throw new NullPointerException();
}
}
+2
sdasdadas
source
to share
public void method1(){
try {
test2();
} catch (IOException ex) {
//catch test2() error
}
}
public void method2() throws IOException{
}
Use throws
+2
Jason
source
to share
This won't happen until you drop it into catch
your block by method2
adding throw e;
.
0
sp00m
source
to share