Erlang / Erlang Advanced Interview questions
What is the difference between error, exit, and throw in Erlang?
All three raise an exception that unwinds the call stack until caught, but they carry different intent and default severity.
| error/1 | exit/1 | throw/1 |
| Signals a programming/runtime error; includes a stack trace; typically left uncaught to crash the process. | Signals intentional process termination; propagates to linked processes as an exit signal. | A lightweight, expected non-local return; meant to be caught by the same code that anticipated it. |
try error(bad_input) %% class = error catch error:Reason -> handle(Reason); exit:Reason -> handle_exit(Reason); throw:Reason -> handle_throw(Reason) end.
The rule of thumb: use throw for expected, local control flow inside code you also control the
catch for; use error for genuine bugs you want visible in crash logs with a stack trace; use
exit when you specifically want to terminate a process and have that termination propagate to
anything linked to it.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
