November 2017
Beginner
316 pages
6h 40m
English
The throw() function does not throw an exception as soon as it encounters one. It immediately throws an error when called. Looking over the official documentation, this is what it says:
throw(e) Throw an object as an exception.
Here, e is any object. throw will convert it into an exception.
julia> throw("")ERROR: ""julia> throw(3+3)ERROR: 6julia> throw("some error message")ERROR: "some error message"julia> throw(ErrorException("an ErrorException has occurred"))ERROR: an ErrorException has occurred
To correctly throw a TypeError, you must actually throw an instance of the object. An instance can be created using type TypeError constructor.:
julia> function say_hi(name) if typeof(name) != String throw(TypeError) else println("hi ...Read now
Unlock full access