Professional Documents
Culture Documents
Discussion Forum Unit 1 Cs2203
Discussion Forum Unit 1 Cs2203
The computer program is the one responsible for catching and handling exceptions. An
“exception” is simply an “error” that happens to arise during the execution of the computer
program causing it to crash or affect the flow in which the program works (Eck, 2019).
Thinking about it, the computer does not handle exceptions automatically, basically we must
code the catching and handling exceptions making the computer program do it.
To be clearer I will show an example of exceptions and crash, using simple math, the program
cannot divide 6 by 0 in line 5 of this program causing the final message as shown.
And the other expressions like 6/3 and 6/2 are not printed because the program crash.
By using try and catch statement, we can catch, and handle exceptions as shown:
In this case the message displays all the results, using catch try and catch statement 6/0 came
with an exception but we can handle it, causing that the program does not crash, and the
outputs are shown in the console.
Reference
Eck, D. J. (2019). Introduction to programming using Java, version 8.1. Hobart and William
Smith Colleges. http://math.hws.edu/javanotes.