VB likes to make this nice and available, it just seems so easy with VB, until you need real power. People tend to dismiss Perl's exception handling and error catching mechanisms as brute force - but they are flexible and powerful. I have found that the latter is more desireable.

In Perl, all expressions evalute to a value - if that value is non-zero, then it is true. Say you want to know if a worksheet is missing:

# lots of code assumed before this line my $oWkS = $oBook->{Worksheet}[$sheet] or die "sheet doesn't exist";
It's really that simple. If it's exception handling you need, Perl provides that via eval and die:
eval { open FILE, $file; } die "$file did not open for reading" if $@;
When you place you questionable code inside an eval block, any errors will be stored in $@ - the trick is you have to check $@ _immediately_ after a possible exception, the next exception will wipe out the first.

When looping, the next and last commands are very valuable:

while (1) { next if $_ = 'just skip this'; last if $_ = 'fatal exception'; }
That was a very simple and pointless example just to get the point across. next and last are very consise ways to handle exceptions.

You can also find CPAN modules that take care of this for you, such as Error.

If you feel you need a centralized repository for errors, just create your own Errors Object. I discussed this very thing in (jeffa) Re: style for returning errors from subroutines, but that solution will have to be re-constructed to fit your needs. The idea is there, however.

Good luck, i hope my pointers help, i am sure that others will supply alternatives . . . :)

Jeff

R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
L-L--L-L--L-L--L-L--L-L--L-L--L-L--

In reply to (jeffa) Re: OLE error handling by jeffa
in thread OLE error handling by denap

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.