Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 11. Warnings > Item 101. Use die to generate exceptions

Item 101. Use die to generate exceptions

Some people have habits left over from the old C-programmer style, where they return a success code after every function. For instance, to signal an error from a subroutine, they might return undef:

sub do_work {
  my $task = shift;

  if ( $task < 0 ) {
    return;  # error, returning undef
  }

  ...;
}


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint