try-catch-finally
try-catch-finally
. It's OK without the catch clause
.try clause
and one finally clause
can be described. You can write multiple catch clause
s.return statement
in both the catch clause
and the finally clause
↓
public class Test {
public static void main(String... args) {
System.out.println(getException());
}
private static String getException() {
try {
throw new Exception();
} catch (Exception e) {
return "catch!";
} finally {
return "finally!";
}
}
}
The execution result is
finally!
Throwable
-> Error
-> Exception
-> RuntimeException
Error
StackOverFlow
try-catch
and throws
are not enforced, can be writtenand
RuntimeException`Exception
RuntimeException
and its subclassestry-catch
or throws
RuntimeException
try-catch
and throws
are not enforced, can be writtenRecommended Posts