Exception Caveats and Built-in Exceptions

Learn about exception caveats and built-in exceptions in Perl.

We'll cover the following

Exception caveats

Though throwing exceptions is simple, catching them is less so. Using $@ correctly requires us to navigate several subtle risks:

  • Unlocalized uses in the same or a nested dynamic scope may modify $@.
  • $@ may contain an object that returns a false value in boolean context.
  • A signal handler (especially the die signal handler) may change $@.
  • The destruction of an object during scope exit may call eval and change $@.

Get hands-on with 1200+ tech skills courses.