in reply to Catching error in DateTime::Format
A safer pattern is
or for simpler cases,unless (eval { ...; 1 }) { ... # handle the error in $@ }
Eval is guaranteed to return a false value on an exception, so you ensure your expression ends with a true value, and now you aren't at the mercy of the exception text/object.eval { ...; 1 } or return undef; return undef unless eval { ...; 1 };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Catching error in DateTime::Format
by ysth (Canon) on Oct 29, 2025 at 19:06 UTC | |
by hippo (Archbishop) on Oct 30, 2025 at 09:47 UTC | |
by ikegami (Patriarch) on Oct 30, 2025 at 02:09 UTC |