Skip to content

Commit 41f8b62

Browse files
lukaszsamsonNezteb
authored andcommitted
Improve documentation on Exception.message and Exception.blame (elixir-lang#14542)
1 parent 695deb3 commit 41f8b62

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/elixir/lib/exception.ex

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ defmodule Exception do
8282

8383
@doc """
8484
Gets the message for an `exception`.
85+
86+
This function will invoke the `c:message/1` callback on the exception
87+
module to retrieve the message. If the callback raises an exception or
88+
returns a non-binary value, this function will rescue the error and
89+
return a descriptive error message instead.
8590
"""
8691
@spec message(t) :: String.t()
8792
def message(%module{__exception__: true} = exception) do
@@ -153,7 +158,7 @@ defmodule Exception do
153158
end
154159

155160
@doc """
156-
Normalizes and formats throw/errors/exits and stacktraces.
161+
Normalizes and formats throws/errors/exits and stacktraces.
157162
158163
It relies on `format_banner/3` and `format_stacktrace/1`
159164
to generate the final format.
@@ -193,14 +198,18 @@ defmodule Exception do
193198
end
194199

195200
@doc """
196-
Attaches information to exceptions for extra debugging.
201+
Attaches information to throws/errors/exits for extra debugging.
197202
198203
This operation is potentially expensive, as it reads data
199204
from the file system, parses beam files, evaluates code and
200205
so on.
201206
202-
If the exception module implements the optional `c:blame/2`
203-
callback, it will be invoked to perform the computation.
207+
If `kind` argument is `:error` and the `error` is an Erlang exception, this function will
208+
normalize it. If the `error` argument is an Elixir exception, this function will invoke
209+
the optional `c:blame/2` callback on the exception module if it is implemented.
210+
Unlike `message/1`, this function will not rescue errors - if the callback raises an exception,
211+
the error will propagate to the caller. It is your choice if you want to rescue and return
212+
the original exception, return a different exception, or let it cascade.
204213
"""
205214
@doc since: "1.5.0"
206215
@spec blame(:error, any, stacktrace) :: {t, stacktrace}

0 commit comments

Comments
 (0)