Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 617769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:28:19+00:00 2026-05-13T18:28:19+00:00

I’m coding in Erlang and a I am bit unsure about how to approach

  • 0

I’m coding in Erlang and a I am bit unsure about how to approach error handling, especially after seeing the ugly errors Erlang always returns.

Should I use try catch in Erlang or should I pass back an error token?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:28:19+00:00Added an answer on May 13, 2026 at 6:28 pm

    There are three basic ways to do exception handling in sequential Erlang:

    1. throws (throw(Term))
    2. errors (erlang:error(Reason))
    3. exits (exit(Reason))

    Throws are to be used for non-local returns and some kinds of exception you expect to be able to handle (maybe because they occur often). When that one is raised, you should try and stop it before it gets outside your module. The usual way it is used in the stdlib is to throw a tuple of the kind {error, Reason} which will be caught by a top-level function in a try...catch before returning the tuple to the user. The user can then decide what to do based on that return value.

    Errors, on the other hand, point to non-recoverable exceptions. They’re usually going to require the user to change his code. They include runtime errors like if or case ... of branches that can’t be matched, functions that can’t match or don’t exist, etc. The purpose of this error is to crash, and should not be caught or handled locally to the process in most cases (have a supervisor or monitoring process pick up the error message and then log it for you or handle it for the user at the interface level).

    Exits are to be used when you specifically want the process to terminate. It’s sometimes a bit unclear when to use exits or errors, but the tip I’ve been given is to differentiate the intent.

    Errors and exits seldom should be caught and handled sequentially (you’ve really got to be sure you know how to fix things!), as other process are in place to deal with it. Let it crash.

    (more details: http://learnyousomeerlang.com/errors-and-exceptions)


    The next level is when dealing with errors in a multi-process environment. The standard way to do things at that point is to link processes together (and/or use supervisors) to pick up dead processes and the reason why they did: restart them, log the message, do your maintenance, upgrade while the system keeps rolling.

    You get a new exception function for multiple processes: exit(Pid, Reason). This lets you call ‘exit’ on another process. In this case, error handling has to be done by setting process_flag(trap_exit, true) in the monitor process, after which you can get exit signals through a standard receive expression.

    Note that a special kind of exit, namely exit(Pid, kill) will terminate a process without any possibility to catch it. Other processes linked to Pid should then receive a signal of the form {'EXIT', killed}.

    Using supervision trees is how you make sure your programs keep running. Crashing early is also essential in order to make sure you won’t corrupt anything; the earlier problematic code stops running, the easier it is to clean it all up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
I have text I am displaying in SIlverlight that is coming from a CMS
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.