I am getting an environment variable in one of my functions, and if that variable is not set or empty then I want to raise an exception because the program can’t function without it. What type of exception would yall raise here?
Here’s the list of default exceptions:
https://hexdocs.pm/elixir/ArgumentError.html#content
1 Like
I agree: RuntimeError
, which is a generic base class for application runtime-type errors.
ArgumentError
is more for situations where the wrong sort of thing was given to a function, rather than a bad value, but a type not capturable in guard syntax, such that a FunctionClauseError
is inappropriate.
In particular, changing the environment variables given when running your program would allow the same function to start working, so there clearly wasn’t a problem with the argument given to it: there was a problem with the runtime it was executing in.
Sources:
4 Likes