Skip to content

Erlang Error Handling — try/catch, Exceptions, and 'Let It Crash'

DodaTech Updated 2026-06-29 1 min read

In this tutorial, you will learn about Erlang Error Handling. We cover key concepts, practical examples, and best practices to help you master this topic.

Erlang's approach to errors is unique: "let it crash." Instead of Defensive Programming everywhere, you write code for the happy path and rely on supervisors to restart crashed processes.

Exceptions

%% try/catch
try
    risky_function()
catch
    error:badarg ->
        io:format("Bad argument~n");
    error:{badmatch, _} ->
        io:format("Match failed~n");
    throw:Value ->
        io:format("Thrown: ~p~n", [Value])
    after
        io:format("Always runs~n")
end.

Let It Crash

%% Don't catch — let the supervisor restart
-module(worker).
-export([process/1]).

process(Data) ->
    %% Assume Data is correct — crash if not
    {ok, Parsed} = parse(Data),  %% Crashes if Data is invalid
    Result = transform(Parsed),  %% Crashes if transform fails
    {ok, Result}.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro