1
- import Kernel , except: [ raise: 1 , raise: 2 ]
2
-
3
1
defmodule Kernel do
4
2
@ moduledoc """
5
3
`Kernel` provides the default macros and functions
@@ -1994,8 +1992,7 @@ defmodule Kernel do
1994
1992
1995
1993
case is_atom ( expanded ) do
1996
1994
false ->
1997
- raise ArgumentError ,
1998
- message: "invalid arguments for use, expected an atom or alias as argument"
1995
+ :erlang . error ArgumentError . exception ( message: "invalid arguments for use, expected an atom or alias as argument" )
1999
1996
true ->
2000
1997
quote do
2001
1998
require unquote ( expanded )
@@ -2632,8 +2629,8 @@ defmodule Kernel do
2632
2629
new_acc =
2633
2630
case condition do
2634
2631
{ :_ , _ , atom } when is_atom ( atom ) ->
2635
- raise ArgumentError , message: << "unbound variable _ inside cond. " ,
2636
- "If you want the last clause to match, you probably meant to use true ->" >>
2632
+ :erlang . error ArgumentError . exception ( message: << "unbound variable _ inside cond. " ,
2633
+ "If you want the last clause to match, you probably meant to use true ->" >> )
2637
2634
x when is_atom ( x ) and not x in [ false , nil ] ->
2638
2635
clause
2639
2636
_ ->
@@ -3075,7 +3072,7 @@ defmodule Kernel do
3075
3072
end
3076
3073
3077
3074
defp pipeline_op ( _ , arg ) do
3078
- raise ArgumentError , message: "unsupported expression in pipeline |> operator: #{ Macro . to_string arg } "
3075
+ :erlang . error ArgumentError . exception ( message: "unsupported expression in pipeline |> operator: #{ Macro . to_string arg } " )
3079
3076
end
3080
3077
3081
3078
@ doc """
@@ -3100,12 +3097,10 @@ defmodule Kernel do
3100
3097
3101
3098
"""
3102
3099
@ spec raise ( binary | atom | tuple ) :: no_return
3103
- def raise ( msg ) when is_binary ( msg ) do
3104
- :erlang . error RuntimeError [ message : msg ]
3105
- end
3106
-
3107
- def raise ( exception ) do
3108
- raise ( exception , [ ] )
3100
+ defmacro raise ( msg ) when is_binary ( msg ) do
3101
+ quote do
3102
+ :erlang . error RuntimeError [ message : unquote ( msg ) ]
3103
+ end
3109
3104
end
3110
3105
3111
3106
@ doc """
@@ -3126,8 +3121,16 @@ defmodule Kernel do
3126
3121
3127
3122
"""
3128
3123
@ spec raise ( tuple | atom , list ) :: no_return
3129
- def raise ( exception , args ) do
3130
- :erlang . error exception . exception ( args )
3124
+ defmacro raise ( exception , args // [ ] ) do
3125
+ quote do
3126
+ exception = unquote ( exception )
3127
+ case exception do
3128
+ e when is_binary ( e ) ->
3129
+ :erlang . error RuntimeError . new ( message: exception )
3130
+ _ ->
3131
+ :erlang . error exception . exception ( unquote ( args ) )
3132
+ end
3133
+ end
3131
3134
end
3132
3135
3133
3136
@ doc """
@@ -3268,15 +3271,15 @@ defmodule Kernel do
3268
3271
{ :error , _ } ->
3269
3272
:elixir_aliases . ensure_loaded ( caller . line , caller . file , atom , caller . context_modules )
3270
3273
_ ->
3271
- raise ArgumentError , message: "cannot use module #{ inspect atom } in access protocol because it does not export __record__/1"
3274
+ :erlang . error ArgumentError . exception ( message: "cannot use module #{ inspect atom } in access protocol because it does not export __record__/1" )
3272
3275
end
3273
3276
end
3274
3277
3275
3278
Record . access ( atom , fields , args , caller )
3276
3279
false ->
3277
3280
case caller . in_match? do
3278
- true -> raise ArgumentError , message: << "the access protocol cannot be used inside match clauses " ,
3279
- "(for example, on the left hand side of a match or in function signatures)" >>
3281
+ true -> :erlang . error ArgumentError . exception ( message: << "the access protocol cannot be used inside match clauses " ,
3282
+ "(for example, on the left hand side of a match or in function signatures)" >> )
3280
3283
false -> quote do: Access . access ( unquote ( element ) , unquote ( args ) )
3281
3284
end
3282
3285
end
@@ -3327,14 +3330,14 @@ defmodule Kernel do
3327
3330
funs = Macro . escape ( funs , unquote: true )
3328
3331
quote bind_quoted: [ funs: funs , opts: opts ] do
3329
3332
target = Keyword . get ( opts , :to ) ||
3330
- raise ( ArgumentError , message: "Expected to: to be given as argument" )
3333
+ :erlang . error ArgumentError . exception ( message: "Expected to: to be given as argument" )
3331
3334
3332
3335
append_first = Keyword . get ( opts , :append_first , false )
3333
3336
3334
3337
lc fun inlist List . wrap ( funs ) do
3335
3338
case Macro . extract_args ( fun ) do
3336
3339
{ name , args } -> :ok
3337
- :error -> raise ArgumentError , message: "invalid syntax in defdelegate #{ Macro . to_string ( fun ) } "
3340
+ :error -> :erlang . error ArgumentError . exception ( message: "invalid syntax in defdelegate #{ Macro . to_string ( fun ) } " )
3338
3341
end
3339
3342
3340
3343
actual_args =
@@ -3581,7 +3584,7 @@ defmodule Kernel do
3581
3584
mod = case modifiers do
3582
3585
[ ] -> ?s
3583
3586
[ mod ] when mod in [ ?s , ?a , ?c ] -> mod
3584
- _else -> raise ArgumentError , message: "modifier must be one of: s, a, c"
3587
+ _else -> :erlang . error ArgumentError . exception ( message: "modifier must be one of: s, a, c" )
3585
3588
end
3586
3589
3587
3590
case is_binary ( string ) do
0 commit comments