I was reading the docs carefully, and this section seems confuse:
The section starts with the example of “Suppose we want to stop execution immediately if the square root of a negative number is taken.”, and defines a custom exception for a sqrt function, etc.
However, the standard sqrt
also stops the execution immediately if the argument is negative (or it does not?).
Thus, it is not clear to me if the example is only showing the custom definition of an error message, or if there is something else under the hood that should be explained.
Similarly, it is not clear in the previous section, Throw function, which is the utility of defining custom exception errors, or even what exception types provide besides a different error message each. I guess that we can catch the type of error in a try
block and deal with it later. In that case probably the Try
section should come before that?
In the way it is organized and written, one has impression that standard exception errors will not stop the program immediately, and that one should read the output as something like r = sqrt(-1) ; if r isa(Error)
etc, and if we wanted that they stop the program, a new custom error must be defined for the function in question.
4 posts - 3 participants