NAME
TOON::Error - Exception object for TOON parse and encode errors
SYNOPSIS
use TOON;
eval { TOON->new->decode($bad_input) };
if (my $err = $@) {
printf "Error: %s\n", $err->message;
printf " at line %d, column %d (offset %d)\n",
$err->line, $err->column, $err->offset;
}
DESCRIPTION
TOON::Error is thrown by TOON and TOON::PP whenever a parse or encode error is encountered. The object stringifies to a human-readable message of the form:
<message> at line <line>, column <column>
METHODS
new
my $err = TOON::Error->new(
message => 'Unexpected character',
line => 3,
column => 7,
offset => 42,
);
Creates and returns a new TOON::Error object. All parameters are optional and default to sensible values (message: 'Unknown TOON error', line: 1, column: 1, offset: 0).
message
my $msg = $err->message;
Returns the human-readable description of the error.
line
my $line = $err->line;
Returns the 1-based line number in the input at which the error occurred.
column
my $col = $err->column;
Returns the 1-based column number in the input at which the error occurred.
offset
my $offset = $err->offset;
Returns the 0-based character offset in the input at which the error occurred.
as_string
my $str = "$err"; # or $err->as_string
Returns a string representation of the error in the form <message> at line <line>, column <column>. This method is also invoked automatically when the object is used in a string context.
AUTHOR
Dave Cross <dave@perlhacks.com>