On Fri, 28 Apr 2000 16:12:44 -0700, Frank Merrow <[EMAIL PROTECTED]>
wrote:

>In dealing with COM objects, often undef is returned if something goes wrong.
>
>I currently have code which looks like this:
>
>...
>SomeCOMTHING -> callthis() || die "this failed"
>SomeCOMTHING -> callthat() || die "that failed"
>...
>
>As you can imagine the code looks ugly and is annoying to code.
>
>Is there anything in Perl like a C++ try/catch block or some other way to say
>
>"If anything in the following code return undef() die"

The next version of Win32::OLE (0.12, already on CPAN but not in
ActivePerl 613) allows you to set the "Warn" option to a CODE reference in
addition to the 0..3 values.  Combined with a non-local goto you can write
code like this:


    Win32::OLE->Option(Warn => sub {goto CheckError});
    # ... your normal OLE code here ...

  CheckError:
    # ... your error handling code here ...


You can simulate this right now with

    Win32::OLE->Option(Warn => 3);
    eval {
        # ... your normal OLE code here ...
    }
    if ($@) {
        # ... your error handling code here ...
    }

Of course checking for OLE errors is different from testing for undef
return values, but I guess you might be talking about the same situations.
You might also have to check the value of $@ to find out, if this really
has been an OLE error or if something else has died on you.

-Jan


---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
         [EMAIL PROTECTED]
For non-automated Mailing List support, send email to  
         [EMAIL PROTECTED]

Reply via email to