++ed by:

1 PAUSE user
1 non-PAUSE user.

Georgy Bazhukov
and 1 contributors


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


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


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.


  package MyFile {
    use Pony::Object qw/:exceptions/;
    protected 'file';
    protected 'data' => undef;
    sub init : Public($this, $file) {
      $this->file = $file;
    sub read : Public($this) {
      $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;


Copyright (C) 2011 - 2017, 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.