NAME

LINQ::Exception - exceptions thrown by LINQ

DESCRIPTION

When LINQ encounters an error, it doesn't just die with a string, but throws an exception object which can be caught with eval, Try::Tiny, or Syntax::Keyword::Try.

These objects overload stringification, so if they are not caught and dealt with, you'll get a sensible error message printed.

EXCEPTION TYPES

LINQ::Exception

This is the base class for all LINQ exceptions.

  use LINQ qw( LINQ );
  use Syntax::Keyword::Try qw( try :experimental );
  
  try {
    my $collection = LINQ [ 1, 2, 3 ];
    my $item       = $collection->element_at( 10 );
  }
  catch ( $e isa LINQ::Exception ) {
    printf(
      "Got error: %s at %s (%s line %d)\n",
      $e->message,
      $e->package,
      $e->file,
      $e->line,
    );
  }

The class provides message, package, file, and line methods to get details of the error, as well as a to_string method which provides the message, package, file, and line as one combined string.

There is a class method throw which instantiates a new object and dies.

  'LINQ::Exception'->throw;

LINQ::Exception is never directly thrown by LINQ, but subclasses of it are.

LINQ::Exception::Unimplemented

A subclass of LINQ::Exception thrown when you call a method or feature which is not implemented for the collection you call it on.

LINQ::Exception::InternalError

A subclass of LINQ::Exception thrown when an internal error is encountered in LINQ, not caused by the caller.

LINQ::Exception::CallerError

A subclass of LINQ::Exception thrown when the caller of a method has called it incorrectly. For example, if a method is called which expects a coderef as a parameter, but is given a string.

LINQ::Exception::CollectionError

A subclass of LINQ::Exception thrown when a method you've called cannot be fulfilled by the collection you've called it on. For example, you've asked to fetch the third item in a collection containing only two items.

LINQ::Exception::NotFound

A subclass of LINQ::Exception::CollectionError thrown when trying to access an item in a collection which cannot be found.

LINQ::Exception::MultipleFound

A subclass of LINQ::Exception::CollectionError thrown when trying to access a single item in a collection when multiple items are found.

LINQ::Exception::Cast

A subclass of LINQ::Exception::CollectionError thrown when trying to cast all items in a collection to a type, but this fails for one or more items.

BUGS

Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=LINQ.

SEE ALSO

LINQ.

AUTHOR

Toby Inkster <tobyink@cpan.org>.

COPYRIGHT AND LICENCE

This software is copyright (c) 2014, 2021 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

DISCLAIMER OF WARRANTIES

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.