Camelia

class Exception

src
    class Exception { ... }

 
All exceptions that are placed into the $! variable (or into $_ in CATCH blocks) inherit from Exception . When you call die or fail with a non-Exception argument, it is wrapped into an X::AdHoc object, which also inherits from Exception . User-defined exception classes should inherit from Exception too, and define at least a method message .
    class X::YourApp::SomeError is Exception {
        method message() {
            "A YourApp-Specific error occurred: out of coffee!";
        }
    }

 

Methods

message

    method message(Exception:D:) returns Str:D

 
This is a stub that must be overwritten by subclasses, and should return the exception message. Special care should be taken that this method does not produce an exception itself.

backtrace

    method backtrace(Exception:D:) returns Backtrace:D

 
Returns the backtrace associated with the exception. Only makes sense on exceptions that have been thrown at least once.

throw

    method throw(Exception:D:)

 
Throws the exception.

rethrow

    method rethrow(Exception:D:)

 
Rethrows an exception that has already been thrown at least once. This is different from throw in that it preserves the original backtrace.

fail

    method fail(Exception:D:)

 
Same as fail $exception ; i.e., it exits the calling Routine and returns the exception wrapped in a L<Failure> object.

gist

    multi method gist(Exception:D:)

 
Returns whatever the exception printer should produce for this exception. The default implementation returns message and backtrace separated by a newline.

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: