Kernel.raise
You're seeing just the macro
raise
, go back to Kernel module for more information.
Raises an exception.
If message
is a string, it raises a RuntimeError
exception with it.
If message
is an atom, it just calls raise/2
with the atom as the first
argument and []
as the second one.
If message
is an exception struct, it is raised as is.
If message
is anything else, raise
will fail with an ArgumentError
exception.
Examples
iex> raise "oops"
** (RuntimeError) oops
try do
1 + :foo
rescue
x in [ArithmeticError] ->
IO.puts("that was expected")
raise x
end
Raises an exception.
Calls the exception/1
function on the given argument (which has to be a
module name like ArgumentError
or RuntimeError
) passing attributes
in order to retrieve the exception struct.
Any module that contains a call to the defexception/1
macro automatically
implements the Exception.exception/1
callback expected by raise/2
.
For more information, see defexception/1
.
Examples
iex> raise(ArgumentError, "Sample")
** (ArgumentError) Sample