class X::Attribute::Undeclared

Compilation error due to an undeclared attribute

class X::Attribute::Undeclared is X::Undeclared { }

Thrown when code refers to an attribute that has not been declared.

For example the code

class A { method m { $!notthere } }

Produces the error

Attribute $!notthere not declared in class A

Methods

method package-kind

Returns the kind of package the attribute was used in (for example class, grammar)

method package-name

Returns the name of the package in which the offensive attribute reference was performed.

Type Graph

Type relations for X::Attribute::Undeclared
perl6-type-graph X::Attribute::Undeclared X::Attribute::Undeclared X::Undeclared X::Undeclared X::Attribute::Undeclared->X::Undeclared Mu Mu Any Any Any->Mu Exception Exception Exception->Any X::Comp X::Comp X::Comp->Exception X::Undeclared->Exception X::Undeclared->X::Comp

Stand-alone image: vector

Routines supplied by class X::Undeclared

X::Attribute::Undeclared inherits from class X::Undeclared, which provides the following routines:

(X::Undeclared) method symbol

Returns the name of the undeclared symbol

(X::Undeclared) method what

Returns the kind of symbol that was not declared (for example variable, type, routine).

Since The symbol wasn't declared, the compiler sometimes has to guess (or rather disambiguate) what kind of symbol it encounter that wasn't declared. For example if you write

say a;

Then the disambiguation defaults to reporting a missing subroutine, even though declaring a constant a = 'a' would also make the error go away.

Routines supplied by role X::Comp

X::Attribute::Undeclared inherits from class X::Undeclared, which does role X::Comp, which provides the following routines:

(X::Comp) method filename

The filename in which the compilation error occurred

(X::Comp) method line

The line number in which the compilation error occurred.

(X::Comp) method column

The column number of location where the compilation error occurred. (Rakudo does not implement that yet).

Routines supplied by class Exception

X::Attribute::Undeclared inherits from class Exception, which provides the following routines:

(Exception) method message

Defined as:

method message(Exception:D: --> 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.

try die "Something bad happened";
if ($!{
    say $!.message# OUTPUT: «Something bad happened.␤» 
}

(Exception) method backtrace

Defined as:

method backtrace(Exception:D: --> Backtrace:D)

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

try die "Something bad happened";
if ($!{
    print $!.backtrace;
}

(Exception) method throw

Defined as:

method throw(Exception:D:)

Throws the exception.

my $exception = X::AdHoc.new;    # Totally fine 
try $exception.throw;            # Throws 
if ($!{ #`( some handling ) }# Suppress the exception 

(Exception) method resume

Defined as:

method resume(Exception:D:)

Resumes control flow where .throw left it when handled in a CATCH block.

# For example, resume control flow for any exception 
CATCH { default { .resume } }

(Exception) method rethrow

Defined as:

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.

my $e = X::AdHoc.new(payload => "Bad situation");
sub f() { die 'Bad' };
sub g() { try fCATCH { default { .rethrow } } };
g;
CATCH { default { say .backtrace.full } };

(Exception) method fail

Defined as:

multi sub    fail(*@text)
multi sub    fail(Exception $e)
method fail(Exception:D:)

Exits the calling Routine and returns a Failure object wrapping the exception $e - or, for the *@text form, an X::AdHoc exception constructed from the concatenation of @text. If the caller activated fatal exceptions via the pragma use fatal;, the exception is thrown instead of being returned as a Failure.

sub copy-directory-tree ($dir{
    fail "$dir is not a directory" if !$dir.IO.d;
    ...
}

(Exception) method gist

Defined as:

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.

my $e = X::AdHoc.new(payload => "This exception is pretty bad");
try $e.throw;
if ($!{ say $!.gist};
# OUTPUT: «This exception is pretty bad 
#   in block <unit> at <unknown file> line 1␤» 

(Exception) sub die

Defined as:

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.

(Exception) sub warn

Defined as:

multi sub warn(*@message)

Throws a resumable warning exception, which is considered a control exception, and hence is invisible to most normal exception handlers. The outermost control handler will print the warning to $*ERR. After printing the warning, the exception is resumed where it was thrown. To override this behavior, catch the exception in a CONTROL block. A quietly {...} block is the opposite of a try {...} block in that it will suppress any warnings but pass fatal exceptions through.

To simply print to $*ERR, please use note instead. warn should be reserved for use in threatening situations when you don't quite want to throw an exception.

warn "Warning message";