in reply to OLE error handling
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:
It's really that simple. If it's exception handling you need, Perl provides that via eval and die:# lots of code assumed before this line my $oWkS = $oBook->{Worksheet}[$sheet] or die "sheet doesn't exist";
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.eval { open FILE, $file; } die "$file did not open for reading" if $@;
When looping, the next and last commands are very valuable:
That was a very simple and pointless example just to get the point across. next and last are very consise ways to handle exceptions.while (1) { next if $_ = 'just skip this'; last if $_ = 'fatal exception'; }
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--
|
|---|