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
@@ -2015,8 +2013,7 @@ defmodule Kernel do
2015
2013
2016
2014
case is_atom ( expanded ) do
2017
2015
false ->
2018
- raise ArgumentError ,
2019
- message: "invalid arguments for use, expected an atom or alias as argument"
2016
+ :erlang . error ArgumentError . exception ( message: "invalid arguments for use, expected an atom or alias as argument" )
2020
2017
true ->
2021
2018
quote do
2022
2019
require unquote ( expanded )
@@ -2652,8 +2649,8 @@ defmodule Kernel do
2652
2649
new_acc =
2653
2650
case condition do
2654
2651
{ :_ , _ , atom } when is_atom ( atom ) ->
2655
- raise ArgumentError , message: << "unbound variable _ inside cond. " ,
2656
- "If you want the last clause to match, you probably meant to use true ->" >>
2652
+ :erlang . error ArgumentError . exception ( message: << "unbound variable _ inside cond. " ,
2653
+ "If you want the last clause to match, you probably meant to use true ->" >> )
2657
2654
x when is_atom ( x ) and not x in [ false , nil ] ->
2658
2655
clause
2659
2656
_ ->
@@ -3095,7 +3092,7 @@ defmodule Kernel do
3095
3092
end
3096
3093
3097
3094
defp pipeline_op ( _ , arg ) do
3098
- raise ArgumentError , message: "unsupported expression in pipeline |> operator: #{ Macro . to_string arg } "
3095
+ :erlang . error ArgumentError . exception ( message: "unsupported expression in pipeline |> operator: #{ Macro . to_string arg } " )
3099
3096
end
3100
3097
3101
3098
@ doc """
@@ -3120,12 +3117,10 @@ defmodule Kernel do
3120
3117
3121
3118
"""
3122
3119
@ spec raise ( binary | atom | tuple ) :: no_return
3123
- def raise ( msg ) when is_binary ( msg ) do
3124
- :erlang . error RuntimeError [ message : msg ]
3125
- end
3126
-
3127
- def raise ( exception ) do
3128
- raise ( exception , [ ] )
3120
+ defmacro raise ( msg ) when is_binary ( msg ) do
3121
+ quote do
3122
+ :erlang . error RuntimeError [ message : unquote ( msg ) ]
3123
+ end
3129
3124
end
3130
3125
3131
3126
@ doc """
@@ -3146,8 +3141,16 @@ defmodule Kernel do
3146
3141
3147
3142
"""
3148
3143
@ spec raise ( tuple | atom , list ) :: no_return
3149
- def raise ( exception , args ) do
3150
- :erlang . error exception . exception ( args )
3144
+ defmacro raise ( exception , args // [ ] ) do
3145
+ quote do
3146
+ exception = unquote ( exception )
3147
+ case exception do
3148
+ e when is_binary ( e ) ->
3149
+ :erlang . error RuntimeError . new ( message: exception )
3150
+ _ ->
3151
+ :erlang . error exception . exception ( unquote ( args ) )
3152
+ end
3153
+ end
3151
3154
end
3152
3155
3153
3156
@ doc """
@@ -3288,15 +3291,15 @@ defmodule Kernel do
3288
3291
{ :error , _ } ->
3289
3292
:elixir_aliases . ensure_loaded ( caller . line , caller . file , atom , caller . context_modules )
3290
3293
_ ->
3291
- raise ArgumentError , message: "cannot use module #{ inspect atom } in access protocol because it does not export __record__/1"
3294
+ :erlang . error ArgumentError . exception ( message: "cannot use module #{ inspect atom } in access protocol because it does not export __record__/1" )
3292
3295
end
3293
3296
end
3294
3297
3295
3298
Record . access ( atom , fields , args , caller )
3296
3299
false ->
3297
3300
case caller . in_match? do
3298
- true -> raise ArgumentError , message: << "the access protocol cannot be used inside match clauses " ,
3299
- "(for example, on the left hand side of a match or in function signatures)" >>
3301
+ true -> :erlang . error ArgumentError . exception ( message: << "the access protocol cannot be used inside match clauses " ,
3302
+ "(for example, on the left hand side of a match or in function signatures)" >> )
3300
3303
false -> quote do: Access . access ( unquote ( element ) , unquote ( args ) )
3301
3304
end
3302
3305
end
@@ -3347,14 +3350,14 @@ defmodule Kernel do
3347
3350
funs = Macro . escape ( funs , unquote: true )
3348
3351
quote bind_quoted: [ funs: funs , opts: opts ] do
3349
3352
target = Keyword . get ( opts , :to ) ||
3350
- raise ( ArgumentError , message: "Expected to: to be given as argument" )
3353
+ :erlang . error ArgumentError . exception ( message: "Expected to: to be given as argument" )
3351
3354
3352
3355
append_first = Keyword . get ( opts , :append_first , false )
3353
3356
3354
3357
lc fun inlist List . wrap ( funs ) do
3355
3358
case Macro . extract_args ( fun ) do
3356
3359
{ name , args } -> :ok
3357
- :error -> raise ArgumentError , message: "invalid syntax in defdelegate #{ Macro . to_string ( fun ) } "
3360
+ :error -> :erlang . error ArgumentError . exception ( message: "invalid syntax in defdelegate #{ Macro . to_string ( fun ) } " )
3358
3361
end
3359
3362
3360
3363
actual_args =
@@ -3616,7 +3619,7 @@ defmodule Kernel do
3616
3619
IO . write "%w()b is deprecated, please use %w()s instead\n #{ Exception . format_stacktrace } "
3617
3620
?s
3618
3621
[ mod ] when mod in [ ?s , ?a , ?c ] -> mod
3619
- _else -> raise ArgumentError , message: "modifier must be one of: s, a, c"
3622
+ _else -> :erlang . error ArgumentError . exception ( message: "modifier must be one of: s, a, c" )
3620
3623
end
3621
3624
3622
3625
case is_binary ( string ) do
0 commit comments