`error` vs `throw(ArgumentError(...))`


#1

Hi guys!

I just want to know the best practice here. In my package, if I see an error related to an wrong input argument (like using -1 for orbit eccentricity), then is it better to use error ou throw(ArgumentError(...)) to the user? I asked on slack but I got mixed results.


#2

I would use ArgumentError or DomainError. Being more specific is just informative to the user (as neither of these errors would be something that you would routinely catch). Cf


#3

Being more specific also allows you to write tests with @test_throws that don’t just pass spuriously if the same type of error is thrown in some other part of the code under test.


#4

Excellent arguments! Thanks guys, I will change all the errors to some more informative.