jeramyRR
Would you raise this as an ArgumentError, RuntimeError, or other?
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:
Most Liked
christhekeele
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:
- Usage of
ArgumentErrorin the Elixir language - Usage of
ArgumentErrorin Elixir libraries - Usage of
RuntimeErrorin the Elixir language - Usage of
RuntimeErrorin Elixir libraries - Behaviour of guard failures:
defmodule Foo, do: def bar(x) when is_list(x), do: :baz try do: Foo.bar(1), rescue: (e -> IO.puts(e.__struct__)) # Elixir.FunctionClauseError
hauleth
RuntimeError








