Skip to content

Commit fe16fd3

Browse files
lukaszsamsonjosevalim
authored andcommitted
Add documentation to Exception callbacks (#13367)
1 parent e520e8c commit fe16fd3

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/elixir/lib/exception.ex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,21 @@ defmodule Exception do
3131
@type arity_or_args :: non_neg_integer | list
3232
@type location :: keyword
3333

34+
@doc """
35+
Receives the arguments given to `raise/2` and returns the exception struct.
36+
37+
The default implementation accepts either a set of keyword arguments
38+
that is merged into the struct or a string to be used as the exception's message.
39+
"""
3440
@callback exception(term) :: t
41+
42+
@doc """
43+
Receives the exception struct and must return its message.
44+
45+
Most commonly exceptions have a message field which by default is accessed
46+
by this function. However, if an exception does not have a message field,
47+
this function must be explicitly implemented.
48+
"""
3549
@callback message(t) :: String.t()
3650

3751
@doc """

lib/iex/test/iex/helpers_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ defmodule IEx.HelpersTest do
802802

803803
assert capture_io(fn -> b(NoMix.run()) end) == "Could not load module NoMix, got: nofile\n"
804804

805-
assert capture_io(fn -> b(Exception.message() / 1) end) ==
805+
assert capture_io(fn -> b(Exception.message() / 1) end) =~
806806
"@callback message(t()) :: String.t()\n\n"
807807

808808
assert capture_io(fn -> b(:gen_server.handle_cast() / 2) end) =~

0 commit comments

Comments
 (0)