I’m wondering if there is a way in java (pure code, not some Eclipse thing) to “syntactic sugar” up repetitive try catch code. Namely, I have to wrap a bunch of functions
public void foo(){
try{
// bla
} catch (Exception e) {
System.out.println("caught exception:");
e.printStackTrace();
}
}
public void bar(){
try{
// other bla
} catch (Exception e) {
System.out.println("caught exception:");
e.printStackTrace();
}
}
and so on. I’d like to write
@excepted public void foo(){
// bla
}
@excepted public void bar(){
// other bla
}
I think sugar of this type was possible in python. Is it possible in Java?
You can’t do something like your pseudocode suggests with annotations, but you can make the method(s) throw:
And just let it bubble up all the way, catching it wherever you want to, higher up the call tree (or down the call stack, if you prefer).