I never did any serious Java coding before, but I learned the syntax, libraries, and concepts based on my existing skills (Delphi & C#). One thing I hardly understand i
Because they haven't learned this trick yet:
class ExceptionUtils {
public static RuntimeException cloak(Throwable t) {
return ExceptionUtils.castAndRethrow(t);
}
@SuppressWarnings("unchecked")
private static X castAndRethrow(Throwable t) throws X {
throw (X) t;
}
}
class Main {
public static void main(String[] args) { // Note no "throws" declaration
try {
// Do stuff that can throw IOException
} catch (IOException ex) {
// Pretend to throw RuntimeException, but really rethrowing the IOException
throw ExceptionUtils.cloak(ex);
}
}
}