Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
The basic issue here, I think, is that, in Perl, "try" is spelled "eval" and "throw" is spelled "die". You've just run into the Perl exception-handling model and wrapping the call in eval is how this is intended to be handled.

So, what to do about it?

The most bare-bones way to deal with it would be

eval { weather_subroutine(); } or do { warn $@; }; # <-- Note trailing semicolon; it *does* matter
You could go even more minimal with
eval { weather_subroutine(); } warn $@ if $@;
but that has some weird edge cases where $@ can get messed up, so the eval { } or do { }; construct is more reliable.

If you want something more robust and/or with more familiar spellings, take a look at TryCatch or Try::Tiny. (The Try::Tiny synopsis shows how to use it to turn an exception into a warning, so you could even lift that example straight out of the docs.)

In reply to Re: Best way to replace 'die' with 'warn' by dsheroh
in thread Best way to replace 'die' with 'warn' by puterboy

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (4)
    As of 2020-10-20 12:02 GMT
    Find Nodes?
      Voting Booth?
      My favourite web site is:

      Results (210 votes). Check out past polls.