erl_error(3)

NAME
erl_error - Utilities for reporting errors.

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()
format_exception(Class, Reason, StackTrace, Options) ->
                    unicode:chardata()

    Types:
        Class = error | exit | throw
        Reason = term()
        StackTrace = [tuple()]
        Options = format_options()

    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