Note that the generic error
function isn’t a good fit here since it obscures the actual error in a generic message. Contrast that with the sqrt
function, which properly throws a DomainError
:
julia> using Test
julia> @test_throws DomainError sqrt(-1)
Test Passed
Thrown: DomainError
which is much easier to explicitly catch and handle. If you want to restrict the function, you can first check the arguments, convert afterwards and work with the converted arguments to get the maximum out of the compiler.