Better exception handling

d3coder admin at xakeps.dk
Sun Mar 21 20:20:31 UTC 2021


Try-catch expression would be really good feature, to avoid exception handling 
bugs, i'm writing code like this:

MyObject myObject;
try {
    myObject = myObjectFactory.newInstance();
} catch(IOException e) {
    throw new CustomException("Can't fetch", e);
}
myObject.doSomething();

Sometimes i do similar code, but with automatic resource handling, e.g.
try(InputStream is = openStream())

Any ideas how this could be made better? I though about try-catch expressions, 
but it's still a lot of a code; I've thought about helper method like 
getOrThrow(supplier, exception -> {}), but it's still feels like a half 
solution

Maybe language can offer something like ? syntax or would be try-catch 
expressions enough?




More information about the amber-dev mailing list