Java Self-learning notes
When designing a program You need to be prepared for the possibility of unexpected errors at runtime: writing_hand:
① try (processing that may cause an exception) ② catch block (catch the exception you want to handle) ③ Finally block (processing performed regardless of whether an exception has occurred) --If you have either catch or finally, you can omit one.
--The try-catch block cannot be described in the finally block. --Multiple finally blocks cannot be described.
--If you want to throw exception handling to the calling class without handling it yourself It is OK (convenient) if you write ** thows exception class name ** in the method signature.
try{
Statement executed if there are no errors
}catch (exception class variable name){
Exception handling (statement executed at the time of exception)
}
What are the exception classes? ■ Error exception: No need to catch with try-catch ■ Exception type exception: If you do not catch it with try-catch, a compile error will occur. ■ RuntimeException-type exception: It is OK with or without catching with try-catch!
try{
Statement executed if there are no errors
}catch (exception class variable name){
Exception handling (statement executed at the time of exception)
}finally{
Process to be executed regardless of whether there are exceptions
}
--------- TBE -------------
Recommended Posts