DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

TryCatch: Simple Try Catch Block In Perl

12.02.2005
| 46687 views |
  • submit to reddit
        
### begin_: file metadata
    ### <region-file_info>
    ### main:
    ###   - name    : TryCatch: try catch block
    ###     desc    : a simple try-catch block example in perl
    ###     date    : created="Thu 2005-12-01 10:58:09"
    ###     last    : lastmod="Thu 2005-12-01 10:58:13"
    ###     tags    : try catch finally error perl cfTryCatch exception
    ### </region-file_info>

### begin_: init perl
    use strict;
    use warnings;

### begin_: try-catch block
    print "begin \n";
    eval{
        ### try block
        print Non_Existent_Function();
    };
    if ($@){
        ### catch block
        print "Failed \n";
    };
    print "end \n";
    

Comments

Snippets Manager replied on Mon, 2012/05/07 - 2:16pm

Haven't tested, but I like! I've used something similar to this in the past but hadn't really looked at it in the same way.