Georgy Bazhukov > Pony-Object-1.00 > Pony::Object::Throwable

Download:
Pony-Object-1.00.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source  

NAME ^

Pony::Object::Throwable - A base throwable object.

OVERVIEW ^

Pony::Object::Throwable objects has throw method which throws an exception.

Exceptions

Do you want to use Pony exceptions in your code? There is nothing easier! Use block try to wrap code with possible exceptions, block catch to catch exceptions and finally to define code, which should be runned after all.

When we talk about exceptions we mean special type of Perl's die. Base class for all pony-exceptions is Pony::Object::Throwable. It has one method throw. It should be used on exceptions in the program.

Use :exceptions (or :try) param to enable try/catch/finally blocks. Use :noexceptions (or notry) param to disable them.

Nested try works for perl-5.14 or higher.

SYNOPSIS ^

  package MyFile;
  use Pony::Object qw/:exceptions/;
    
    protected 'file';
    protected 'data' => undef;
    
    sub init : Public
      {
        my $this = shift;
        ($this->file) = @_;
      }
    
    sub read : Public
      {
        my $this = shift;
        
        $this->data = try {
          open F, $this->file or
            throw Pony::Object::Throwable("Can't find $file.");
          local $/;
          my $data = <F>;
          close F;
          return $data;
        } catch {
          my $e = shift; # get exception object
          say "Exception catched!";
          say $e->dump();
          return undef;
        };
      }
    
  1;

COPYRIGHT AND LICENSE ^

Copyright (C) 2011 - 2013, Georgy Bazhukov.

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.

syntax highlighting: