When I started programming, I would get nervous seeing exceptions and errors pop up in my code, but now that I better understand Java I can write these exceptions myself!
What happens in Java is that when an exception occurs, or is thrown, the program’s normal pace is terminated and it instead marks the exception as being “caught” before entering an exception-handling routine.

There are two kinds of exceptions: checked and unchecked exceptions. Checked exceptions are caught during compile-time when JDK’s compiler first runs through your code. Unchecked exceptions go undiscovered until run-time, which is why they are unchecked.
Specifying exceptions in your code is important because:
- It more easily specifies what went wrong than the default checked exception print statements.
- It helps you improve your bug-tracking skills.
- It helps during testing phase when you run it.
There are 2-3 blocks that can make up a try-catch statement: try, catch, and finally. Try is which operation the exception-handling routine surrounds, remaining content skipped once an exception is found. Catch is the chosen exception. Finally is not always used, but can be used to take ending action regardless of exceptions to ensure certain code is run at the end, such as closing an open data stream.
try {
. . .
} catch (InputMismatchException e){
. . .
} catch (ArrayIndexOutOfBoundsException e){
. . .
}
finally {
objScanner.close();
}
There are different exceptions and multiple can be included by a try-block. You can even make your own! Remember though: only one is chosen. Seek out my code and you can read all about it!
Follow my original code on my GitHub profile!