Module

erl_error

Module Summary

Utilities for reporting errors.

Since

Module erl_error was introduced in OTP 24.0.

Description

This module provides functions for pretty-printing errors and exceptions.

Data Types

format_options() =
    #{column => column(),
      stack_trim_fun => stack_trim_fun(),
      format_fun => format_fun()}

A map with formatting options.

stack_trim_fun() =
    fun((module(), atom(), arity()) -> boolean())

A fun used to trim the end of the stacktrace. It is called with module, function, and arity from an entry from the stacktrace. The fun is to return true if the entry should be trimmed, and false otherwise. The default value is:

fun(_, _, _) -> false end
format_fun() = fun((term(), column()) -> iolist())

A fun used to format function arguments for BIF and function calls. By default the following fun will be used:

fun(Term, I) -> io_lib:print(Term, I, 80, 30) end
column() = integer() >= 1

Start column number. Default is 1.

Exports

format_exception(Class, Reason, StackTrace) -> unicode:chardata()
OTP 24.0
format_exception(Class, Reason, StackTrace, Options) ->
unicode:chardata()
OTP 24.0

Types

Format the error reason and stack back-trace caught using try ... catch in the same style as the shell formats them.

Example:

try
    do_something()
catch
    C:R:Stk ->
        Message = erl_error:format_exception(C, R, Stk),
        io:format(LogFile, "~ts\n", [Message])
end

© 2010–2021 Ericsson AB
Licensed under the Apache License, Version 2.0.