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
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









