About exception handling

I am a beginner in programming. This time, I will output about ** exception handling ** as it is a continuation of the previous ** exception ** article.

Q1: What is exception handling?

** Processing after ** an exception was thrown at run time. (If exception handling is not performed, the system will be interrupted, but if exception handling is performed, the necessary processing can be executed before the interruption.) (Example) ・ Displays "An unexpected error has occurred". -Process to close the file etc ...

Q2: How do you write exception handling?

Write with ** [try → catch → finally] syntax **.

qiita.java


try {
    //What you want to do (an exception may be thrown)
} catch() {
    //Catch when an exception is thrown
} finally {
    //You can write a process that is always performed regardless of whether an exception occurs and is caught.
}

Is it not necessary to write finally separately?

Yes. You don't have to write it separately, just [try → catch]. However, I'm a beginner, so I don't know yet, but I saw an article somewhere that the moment when finally feels very grateful will come someday, so I don't have to write it, but it seems to be important.

[References] https://eng-entrance.com/java-finally

** * If you have any mistakes, I'm sorry, but I would appreciate it if you could let me know in the comments. ** **

Recommended Posts

About exception handling
About exception handling
About Ruby exception handling
Exception handling
Exception handling Exception
[Java] About try-catch exception handling
Java exception handling?
ruby exception handling
Ruby exception handling
[Java] Exception handling
☾ Java / Exception handling
Java exception handling
Java exception handling
[For Java beginners] About exception handling
Exception handling practice (ArithmeticException)
[Ruby] Exception handling basics
Spring Boot exception handling
About the handling of Null
Classes that require exception handling
Java's first exception handling (memories)
[Java] Practice of exception handling [Exception]
[Ruby] Exception handling in functions
exception
Java exception handling usage rules
About =
[Java Silver] (Exception handling) About try-catch-finally and try-with-resource statements
Exception handling techniques in Java
[In-house study session] Java exception handling (2017/04/26)
About error handling of comment function
[Rails] How to write exception handling?
Exception handling with a fluid interface
Step-by-step understanding of Java exception handling
[Introduction to Java] About exception handling (try-catch-finally, checked exception, unchecked exception, throws, throw)
About method.invoke
About Kotlin
About attr_accessor
About Hinemos
About inheritance
About params
About Docker
About Rails 6
About form_for
About Spring ③
[Ruby] Exception handling, give back if given
About enum
About polymorphism
About Optional
About hashes
About JitPack
About Dockerfile
About this ()
About devise
About encapsulation
About Docker
About JAVA_HOME
About active_hash
About static
About exceptions
Self-made Exception
Java (exception handling, threading, collection, file IO)
About scope