Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

when function name end with `!`

enter link description here
What’s the special meaning for ending with ! for function name?

  defp db_host do
    Application.fetch_env!(:my_app, :db_host)
  end

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading