@@ -1483,6 +1483,7 @@ defmodule Kernel do
14831483 differences:
14841484
14851485 1) Differently from records, exceptions are documented by default;
1486+
14861487 2) Exceptions **must** implement `message/1` as API that return a
14871488 binary as result;
14881489
@@ -1519,12 +1520,14 @@ defmodule Kernel do
15191520 case __CALLER__. in_guard? do
15201521 true ->
15211522 quote do
1522- is_tuple ( unquote ( thing ) ) and :erlang . element ( 2 , unquote ( thing ) ) == :__exception__
1523+ is_tuple ( unquote ( thing ) ) and tuple_size ( unquote ( thing ) ) > 1 and
1524+ :erlang . element ( 2 , unquote ( thing ) ) == :__exception__
15231525 end
15241526 false ->
15251527 quote do
15261528 result = unquote ( thing )
1527- is_tuple ( result ) and :erlang . element ( 2 , result ) == :__exception__
1529+ is_tuple ( result ) and tuple_size ( result ) > 1 and
1530+ :erlang . element ( 2 , result ) == :__exception__
15281531 end
15291532 end
15301533 end
@@ -2727,7 +2730,7 @@ defmodule Kernel do
27272730 """
27282731 @spec raise( binary | atom | tuple ) :: no_return
27292732 def raise ( msg ) when is_binary ( msg ) do
2730- :erlang . error RuntimeError . new ( message: msg )
2733+ :erlang . error RuntimeError [ message : msg ]
27312734 end
27322735
27332736 def raise ( exception ) do
@@ -2744,14 +2747,23 @@ defmodule Kernel do
27442747 Any module defined via `defexception` automatically
27452748 defines `exception(args)` that returns a new instance
27462749 of the record and a `exception(args, current)` that
2747- works as no-op.
2750+ updates the current exception.
2751+
2752+ Re-raising an exception will retrieve the previous
2753+ stacktrace so it keps the properties of the original
2754+ exception.
27482755
27492756 ## Examples
27502757
27512758 raise ArgumentError, message: "Sample"
27522759
27532760 """
27542761 @spec raise( tuple | atom , list ) :: no_return
2762+ def raise ( exception , args ) when is_tuple ( exception ) and tuple_size ( exception ) > 1 and
2763+ :erlang . element ( 2 , exception ) == :__exception__ do
2764+ :erlang . raise ( :error , exception . exception ( args ) , :erlang . get_stacktrace )
2765+ end
2766+
27552767 def raise ( exception , args ) do
27562768 :erlang . error exception . exception ( args )
27572769 end
0 commit comments