Error.pm -- trying to catch multiple exceptions

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default Re: Error.pm -- trying to catch multiple exceptions

    In article <g261ivc6640q7u116t0cg7fts0mfkv8fmk@4ax.com>,
    ed <coo_t2-NO-LIKE-SPAM@yahoo.com> writes:
    >Hey all. I'm experiment with Error.pm .
    >It's the module that lets you use Try/Catch blocks to handle
    >exceptions.
    >
    >I was wondering, shouldn't both exceptions below be caught?
    >When I run it, it only catches the first one.
    >
    >It catches either exception, if I only throw one exception at a time.
    >But it _only_ catches one.
    >In other words if I comment out the first line that throws an
    >exception
    >in the try block below, the second one will be thrown and caught.
    >So only the first exception is being caught.
    >
    >Am I using it right or is this the way it's suppose to work?
    That's the way it's supposed to work. An exception is an immediate non-local
    transfer of control. For 'throw' read 'die'. You can only die once, unless
    you're a cat or James Bond, right?

    [snip]
    >try {
    > throw Exception('Exception');
    > throw IOException('IOException');
    >}

    --
    Peter Scott
    [url]http://www.perldebugged.com[/url]
    Peter Scott Guest

  2. Similar Questions and Discussions

    1. global catch error?
      Hi, is it possible to catch ALL uncatched errors of my application? I want to have the possibility to show my own error dialog for all errors...
    2. catch loadMovie error?
      Howdy, it's a "newbie to Flash" question.. sorry! I am using the loadMovie() action but need to be able to catch errors e.g. If the jpg/swf I...
    3. catch 401.2 error
      Dear collegues! I am trying to create a single Login Application, that can either authenticate against a database or against ADSI. Intenal users...
    4. catch an 401.2 error
      Dear collegues! I am trying to create a single Login Application, that can either authenticate against a database or against ADSI. Intenal users...
    5. Catch Exceptions for Asyncronous Invoke
      How can I catch exceptions of web service, when I am using Asyncronouse Invoke (like: myService.BeginGetCustomers()) I want to catch exceptions...
  3. #2

    Default Re: Error.pm -- trying to catch multiple exceptions

    ed <coo_t2-NO-LIKE-SPAM@yahoo.com> wrote in message news:<g261ivc6640q7u116t0cg7fts0mfkv8fmk@4ax.com>. ..
    > Hey all. I'm experiment with Error.pm .
    > It's the module that lets you use Try/Catch blocks to handle
    > exceptions.
    >
    > I was wondering, shouldn't both exceptions below be caught?
    > When I run it, it only catches the first one.
    >
    > It catches either exception, if I only throw one exception at a time.
    > But it _only_ catches one.
    > In other words if I comment out the first line that throws an
    > exception
    > in the try block below, the second one will be thrown and caught.
    > So only the first exception is being caught.
    >
    > Am I using it right or is this the way it's suppose to work?
    [snip]
    > try {
    > throw Exception('Exception');
    > throw IOException('IOException');
    > }
    > catch Exception with {
    > my $e = shift;
    > print Dumper($e);
    > }
    > catch IOException with {
    > my $e = shift;
    > print Dumper($e);
    > };
    This is the way it's supposed to work. When something throws an
    exception, the program execution is stopped. If there is no handler
    for this particular exception, Perl will display an error message and
    the whole program will terminate. If there is a handler, then Perl
    will execute the instructions in the handler and then continue with
    the code *immediately after* the whole try..catch block (well, it will
    execute the instructions in the finally clause, if there is one).

    Thus, when you throw the first exception, no matter whether there is
    an exception handler that will catch it or not, the instructions from
    the 'throw' to the end of the 'try' clause will most certainly *not*
    be executed. This is the way exceptions behave in all languages that
    have them (and that I am familiar with; maybe I should put 'most' there
    instead of 'all'): whenever an exception is thrown, none of the code
    after it in the 'try' clause is executed, because an exception signals
    an, well, exceptional condition - usually some grave problem/error -
    meaning that some operations were not completed and the code that would
    try to use their results would fail in strange and unpredictable ways.

    G'luck,
    Peter
    Peter Pentchev Guest

  4. #3

    Default Re: Error.pm -- trying to catch multiple exceptions

    On 25 Jul 2003 06:54:38 -0700, [email]roam@ringlet.net[/email] (Peter Pentchev)
    wrote:

    >
    >This is the way it's supposed to work.
    Ok, I wasn't sure about that. The language I'm most comfortable with
    is PHP, and it doesn't support try/catch, although PHP 5 will. I
    think I heard that Perl 6 will have them built in too. ?
    I'm trying to get more comfortable with OO-ish way of doing things
    since even the two most popular scripting languages(Perl && PHP) seem
    to be moving more towards it. That and I'd also like to one day be
    comfortable with Java, Python, and C++, which all use try/catch..
    However I've been reading a C++ book lately and it gives me a headache
    every time I pick it up :)

    Thanks all.

    --ed

    ed Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139