concept exception in category erlang

appears as: exception, exception, n exception, exceptions
Erlang and OTP in Action

This is an excerpt from Manning's book Erlang and OTP in Action.

Like many programming languages, Erlang has exception handling for catching errors in a particular piece of code, but it also has a unique system of process links for handling process failures in a effective way, which is what we’re going to talk about here.

Floats are handled using 64-bit IEEE 754-1985 representation (double precision), and the syntax is the same as used by most programming languages, with the exception that whereas many languages allow a floating-point number to begin with a period, as in .01, Erlang requires that it starts with a digit, as in 0.01:

In modern Erlang, you use a try expression to handle exceptions that occur in a piece of code. In most ways, it works like a case expression, and in the simplest form it looks like this:

try
    some_unsafe_function()
catch
    oops         -> got_throw_oops;
    throw:Other  -> {got_throw, Other};
    exit:Reason  -> {got_exit, Reason};
    error:Reason -> {got_error, Reason}
end

Between try and catch, you have the body or protected section. Any exception that occurs within the body and tries to propagate out from it will be caught and matched against the clauses listed between catch and end. If it doesn’t match any of the clauses, the exception will continue as if there was no try expression around the body. Similarly, if the body is evaluated without raising an exception, its result will become the result of the whole expression, as if the try and catch...end had not been there. The only difference is when there is an exception, and it matches one of the clauses. In that case, the result becomes whatever the matching clause returns.

Throwing an exception to end the process

The exit class of exception is meant for terminating the running process. This is thrown using the BIF exit/1: