Exception::NoException - Exception::NoException documentation


Exception-NoException documentation Contained in the Exception-NoException distribution.

Index


Code Index:

SYNOPSIS

Top

Throw non-exception exceptions when you're using die() for flow control and want $@ to appear to be false/empty.

  use Exception::NoException;
  eval {
    die Exception::NoException->new;
  };
  die $@ if $@;

This is most useful when using File::Find::find or similar callback-using functions. You can wrap your call in an eval and stop execution by throwing a non-error. When you look at $@ to see if there's a problem, you won't find any.

METHODS

Top

Exception::NoException->new

This method takes no arguments and returns a new object that acts like an empty string "".

ref

Overloads the built-in function ref and returns "".

EXAMPLES

Top

File::Find::find
 use File::Find;
 use Exception::NoException;

 eval {
     find( sub {
         if ( $File::Find::name =~ /something/ ) {
             # do something with the file
             die Exception::NoException->new;
         }
     } );
 };
 die $@ if $@;

AUTHOR

Top

Josh Jore, <jjore at cpan.org>

BUGS

Top

blessed() will still return true.

Please report any bugs or feature requests to bug-exception-noexception at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Exception-NoException. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Exception::NoException

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Exception-NoException

* CPAN Ratings

http://cpanratings.perl.org/d/Exception-NoException

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Exception-NoException

* Search CPAN

http://search.cpan.org/dist/Exception-NoException

ACKNOWLEDGEMENTS

Top

Yitzchak Scott-Thoennes came up with a problem where an exception object used an eval block during the bool conversion from overload. The following snippet caused him hours of grief and it inspired me to come up with an object where that effect was actually desired. It also happens to solve a common problem with loops that use callbacks.

 # Yitzchak's problem:
 eval {
     die SomeObject->new;
 };
 if ( $@ ) {
     # now $@ is empty.
 }
 package SomeObject;
 use overload bool => sub { eval { } };
 sub new { bless [], shift }

To solve Yitzchak's problem, copy $@ ala my $e = $@ before examining it.

COPYRIGHT & LICENSE

Top


Exception-NoException documentation Contained in the Exception-NoException distribution.

package Exception::NoException;
BEGIN {
  $Exception::NoException::VERSION = '0.07';
}
# ABSTRACT: An exception object that's always false

use strict;

require Exception::NoException::_obj;

sub new {
    my $obj;
    return bless \$obj, "$_[0]::_obj";
}

'The Adventures Of Kung-Fu Jesus and His Amazing Giant Robot';

__END__