die
ErrorsCollection

die

Synthesised documentation from type/Exception

From type/Exception

See Original text in context

multi sub die()
multi sub die(*@message)
multi sub die(Exception:D $e)
method    die(Exception:D:)

Throws a fatal Exception. The default exception handler prints each element of the list to $*ERR (STDERR).

die "Important reason";

If the subroutine form is called without arguments, the value of $! variable is checked. If it is set to a .DEFINITE value, its value will be used as the Exception to throw if it's of type Exception, otherwise, it will be used as payload of X::AdHoc exception. If $! is not .DEFINITE, X::AdHoc with string "Died" as payload will be thrown.

die will print by default the line number where it happens

die "Dead";
# OUTPUT: «(exit code 1) Dead␤ 
# in block <unit> at /tmp/dead.p6 line 1␤␤» 

However, that default behavior is governed at the Exception level and thus can be changed to anything we want by capturing the exception using CATCH. This can be used, for instance, to suppress line numbers.

CATCH {
  default {
    .payload.say
  }
};
die "Dead" # OUTPUT: «Dead␤»