November 2017
Beginner
316 pages
6h 40m
English
This function can be used to raise an ErrorException of a custom type, which the developer wants to show the end user.
It should be noted that the use of this function is generally discouraged outside of debugging and logging. It is almost always better to use a more specific or custom exception.
Taking the example of the previous throw() function, we have:
julia> function say_hi(name :: String)
if length(name) < 5
error("Name less than 5!!!")
else
println("hi $name")
end
end
say_hi (generic function with 1 method)
julia> say_hi("joe")
ERROR: Name less than 5!!!
in say_hi(::String) at ./REPL[33]:3
Here, we have used a custom message of our own, Name less than 5!!!, which gets printed on the screen if the length is less ...
Read now
Unlock full access