Guaranteed code execution in Java
void throwIfTrue(Boolean param) {
try {
if (param)
throw new RuntimeException("test exception");
}
catch (Exception e) {
System.out.println("catch");
}
finally {
System.out.println("finally");
}
}
throwIfTrue(true);
//printed: "catch" and "finally"
throwIfTrue(false);
//printed only "finally"
- Log in to post comments