Re: Do the Monks recommend Try::Tiny for eval work?
by Your Mother (Archbishop) on Oct 30, 2015 at 01:10 UTC
|
Responding because I've linked the docs to the module twice lately. I don't use Try::Tiny (now, I did for awhile). I've just been linking the doc because it's a good overview of problems. I do similar to anonymonk. I didn't know Devel::EvalError either. tye usually knows what he's doing though :P so I'll check it out if I think regular eval{} isn't bringing enough to the table.
| [reply] [d/l] |
|
eval {
...
1
} or do {
my $e = $@ || 'Unknown error';
...
};
And I've been pretty happy with it.
We are still on a Perl version where $@ can be clobbered by a DESTROY, but we just exhaustively fix any DESTROY methods.
If you have less control over your code base(s) and have to deal with less modern versions of Perl, then Devel::EvalError might be very useful (it was very useful to me at a prior job).
| [reply] [d/l] |
Re: Do the Monks recommend Try::Tiny for eval work?
by Anonymous Monk on Oct 29, 2015 at 23:31 UTC
|
I use eval { ...; 1 } or ...;
When I think I need more than that I think about using Devel::EvalError -- Reliably detect if and why eval() failed
Try::Tiny isn't even on my radar :)
| [reply] [d/l] |
|
One I've never heard of. I'll check it out when I get home... thanks! I also like the use of or there... very organic.
| [reply] [d/l] |
Re: Do the Monks recommend Try::Tiny for eval work?
by sam_bakki (Pilgrim) on Oct 30, 2015 at 04:57 UTC
|
Hi
At work, I extensilvely use Try::Tiny. I have many production code with try::Tiny, I highly recommend it.
Here is how use it (Example from my Moose class production code)
#Read the RAWFILE
$self->loggerObj()->logDebug("Reading Data from RAW BIN File ".$in
+RawFile);
try
{
$rawBuffer = read_file( $inRawFile, { binmode => ':raw' } ) ;
}
catch
{
$self->loggerObj()->logError('Can not read RAW BIN File '.$inR
+awFile.' '.$_);
};
| [reply] [d/l] |
Re: Do the Monks recommend Try::Tiny for eval work?
by Athanasius (Archbishop) on Oct 30, 2015 at 09:39 UTC
|
| [reply] |
Re: Do the Monks recommend Try::Tiny for eval work?
by syphilis (Archbishop) on Oct 30, 2015 at 02:06 UTC
|
AFAICR, whenever I eval{...} my only interests are whether $@ has been set and, if so, the contents of $@.
I therefore merely run the eval, then examine the contents of $@.
I guess that if I needed to find out something else, then I'd do something else :-)
Cheers, Rob | [reply] [d/l] |
Re: Do the Monks recommend Try::Tiny for eval work?
by dsheroh (Monsignor) on Oct 30, 2015 at 09:17 UTC
|
I tend to use Try::Tiny. It's simple, it works, and I don't have to think about it. There are definitely other good alternatives (as shown by previous replies), but this is the one that, for me, requires the least (effort|thought). | [reply] |
|
I only started to use Try::Tiny around the time this thread was first posted. Now (over 3 years on) my experience matches dsheroh's. I would only add that the clarity of the syntax for me beats most if not all of the eval idioms. It seems there are several of those and each proponent has their favourite. Anyone else reading them will likely have to stop for a minute and work out what's going on. With try/catch it's clear, even to users of other such modules or even other languages with similar features. For these reasons, and that it is lightweight with no non-core dependencies, I'm very happy to continue to use Try::Tiny.
| [reply] |
Re: Do the Monks recommend Try::Tiny for eval work?
by LanX (Saint) on Oct 30, 2015 at 00:39 UTC
|
Well the monks certainly recommend staying in an active thread instead of starting a new one...
| [reply] |
|
| [reply] |
|
the monastery has no straw poll feature ... unfortunately!
| [reply] |