Pony::Object::Throwable - A base throwable object.
Pony::Object::Throwable objects has throw method which throws an exception.
throw
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.
try
catch
finally
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.
die
Use :exceptions (or :try) param to enable try/catch/finally blocks. Use :noexceptions (or notry) param to disable them.
:exceptions
:try
:noexceptions
notry
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; }; } } 1;
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.
To install Pony::Object, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pony::Object
CPAN shell
perl -MCPAN -e shell install Pony::Object
For more information on module installation, please visit the detailed CPAN module installation guide.