Handling exceptions
To understand how we can handle exceptions, we must first understand what the origins of a problem might be. It is only when we have understood this that we can insert measures to handle them correctly.
Let's return to our function that divides two values. Let's say this function takes two arguments, as it did in our previous example:
function c(x, y) result = x / y end_function
We should assume that this function does something more than just print this single line. We can mark it out with some comments, as follows:
function c(x, y) // The function does some things ere result = x / y // And even more things here // It might even return a value end_function
We know that as this function divides two values, we might get an exception if y
is given a value of 0
.
The first thing we should ask ourselves is if this is the...