Exception
Convenience functions to work with and pretty print exceptions and stacktraces.
Notice that stacktraces in Elixir are updated on errors.
For example, at any given moement, System.stacktrace
will return the stacktrace for the last error that ocurred
in the current process.
That said, many of the functions in this module will
automatically calculate the stacktrace based on the caller,
when invoked without arguments, changing the value of
System.stacktrace. If instead you want to format the
stacktrace of the latest error, you should instead explicitly
pass the System.stacktrace as argument.
Summary
| format_fa(fun, arity) | Receives an anonymous function and arity and formats it as shown in stacktraces. The arity may also be a list of arguments |
| format_file_line(file, line) | Formats the given file and line as shown in stacktraces. If any of the values are nil, they are omitted |
| format_mfa(module, fun, arity) | Receives a module, fun and arity and formats it as shown in stacktraces. The arity may also be a list of arguments |
| format_stacktrace(trace \\ nil) | Formats the stacktrace |
| format_stacktrace_entry(entry) | Receives an stacktrace entry and formats it into a string |
| normalize(exception) | Normalizes an exception, converting Erlang exceptions to Elixir exceptions |
| normalize(arg1, exception) | Normalizes an exception, converting Erlang exceptions to Elixir exceptions |
Types ↑
stacktrace_entry :: {module, function, arity_or_args, location} | {function, arity_or_args, location}
Functions
Receives an anonymous function and arity and formats it as shown in stacktraces. The arity may also be a list of arguments.
Examples
Exception.format_fa(fn -> end, 1)
#=> "#Function<...>/1"
Formats the given file and line as shown in stacktraces. If any of the values are nil, they are omitted.
Examples
iex> Exception.format_file_line("foo", 1)
"foo:1:"
iex> Exception.format_file_line("foo", nil)
"foo:"
iex> Exception.format_file_line(nil, nil)
""
Receives a module, fun and arity and formats it as shown in stacktraces. The arity may also be a list of arguments.
Examples
iex> Exception.format_mfa Foo, :bar, 1
"Foo.bar/1"
iex> Exception.format_mfa Foo, :bar, []
"Foo.bar()"
iex> Exception.format_mfa nil, :bar, []
"nil.bar()"
Anonymous functions are reported as -func/arity-anonfn-count-, where func is the name of the enclosing function. Convert to "anonymous fn in func/arity"
Formats the stacktrace.
A stacktrace must be given as an argument. If not, this function
calculates a new stacktrace based on the caller and formats it. As
a consequence, the value of System.stacktrace is changed.
Specs:
- format_stacktrace_entry(stacktrace_entry) :: String.t
Receives an stacktrace entry and formats it into a string.
Normalizes an exception, converting Erlang exceptions to Elixir exceptions.
Useful when interfacing Erlang code with Elixir code.