, e.printStackTrace(), Exception. , . , func1 func2 Exception s. - ,
class Func1Exception extends Exception {
public Func1Exception(Exception e) {
super(e);
}
}
class Func2Exception extends Exception {
public Func2Exception(Exception e) {
super(e);
}
}
,
private static Object func1Decorator() throws Func1Exception {
try {
return func1();
} catch (Exception e) {
throw new Func1Exception(e);
}
}
private static Object func2Decorator() throws Func2Exception {
try {
return func2();
} catch (Exception e) {
throw new Func2Exception(e);
}
}
Then you can process them however you want.
try {
a = func1Decorator();
b = func2Decorator();
} catch (Func1Exception e) {
} catch (Func2Exception e) {
}
If you want to func2start even in case of failure, you can use the block finally,
try {
a = func1Decorator();
} catch (Func1Exception e) {
} finally {
try {
b = func2Decorator();
} catch (Func2Exception e) {
}
}
source
share