Can I just put a 'try' around it?

Without knowing what your code looks like (SSCCE!), I'd say yes, try (e.g. from Try::Tiny or a modern Perl) is a standard way to catch errors like this and to have your code continue after handling the error. It also depends a bit on how your script is being run and how often this happens, if it doesn't happen all too often and you're running your script as a daemon, note there are process managers that will automatically restart crashed daemons.

Update: Since your last question was about RPi, is this on an RPi? Because there, since Raspbian already runs systemd, I just use that to manage my daemons. For example, here's a .service file I used on a project that used a Mojolicious webserver on an RPi:

# Docs: https://wiki.debian.org/systemd/Services # Set me up via: # $ sudo ln -s /home/pi/project/my_web.service /etc/systemd/system/ # $ sudo systemctl daemon-reload # $ sudo systemctl enable my_web # $ sudo systemctl start my_web [Unit] Description=My Web Service After=network.target [Service] Type=simple Restart=always Environment="PERL5LIB=/home/pi/perl5/lib/perl5" User=pi Group=pi ExecStart=/home/pi/project/web_app.pl daemon -m production -l http://* +:8080 [Install] WantedBy=multi-user.target

You can customize how the service gets managed, e.g. with things like KillSignal=SIGINT or RestartSec=30.


In reply to Re: LWP::Daemon barf on bad DNS (updated) by haukex
in thread LWP::Daemon barf on bad DNS by MikeL

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.