Reputation: 4077
Consider Application.fetch_env!/2
.
What’s the special meaning for ending with !
for a function name?
defp db_host do
Application.fetch_env!(:my_app, :db_host)
end
Upvotes: 0
Views: 215
Reputation: 4096
As explained in the Naming Convention section "Trailing Bang": https://hexdocs.pm/elixir/1.13.4/naming-conventions.html#trailing-bang-foo
A trailing bang (exclamation mark) signifies a function or macro where failure cases raise an exception.
So the function Application.fetch_env!
will raise an ArgumentError
when the configuration parameter does not exist (as stated in the documentation) while Application.fetch_env
(without exclamation mark) will return an :error
in case of a non-existing parameter
Upvotes: 5