Try::T...yClass(3pm)

πŸ“¦
version 0.01 Β· 4 versions
, in debian bookworm, ubuntu noble

πŸ’– Try::Tiny::ByClass β€” the perl manual, but make it cute ✨

okay bestie, gather round, because this is a User Contributed Perl Documentation page for a module called Try::Tiny::ByClass, and it is lowkey iconic πŸŽ€


🌸 NAME 🌸

Try::Tiny::ByClass β€” catch exceptions selectively, by class name πŸ’…

like, not every exception deserves your attention, yk? this one lets you pick and choose πŸ¦‹


✨ SYNOPSIS ✨

here's the whole vibe, verbatim, no cap:

use Try::Tiny::ByClass;

try {
      die $exception_object;
} catch_case [
  'Some::Class' => sub {
    # handle Some::Class exceptions
  },
  'Exception::DivByZero' => sub {
    # handle Exception::DivByZero exceptions
  },
], finally {
  # always do this
};

see how it's giving organized? that's the whole point 🫢


πŸ’œ DESCRIPTION πŸ’œ

okay so. this module is a simple wrapper around Try::Tiny, which see πŸ‘€ (fr fr, go read that one too). It re-exports try, catch, and finally β€” so you get all the classics, bestie πŸ’–

and on top of that, it gives you a way to catch only some exceptions, by filtering on the class of an exception object. and when we say class we mean it in the full sense: superclasses and consumed roles count too, so your subclass energy is very much recognized πŸ‘‘


🧚 Functions 🧚

catch_case ($;@)

this one is intended to be used instead of catch β€” specifically in the second argument position</u> of try 🌈

instead of taking a block like catch does, it takes a reference to an array of CLASS => CODEREF pairs πŸ’« and then it passes that whole thing on to dispatch in Dispatch::Class.

so yeah, it's basically a lil matchmaker between your exceptions and your handlers. slay πŸŽ€


πŸ‘‘ SEE ALSO πŸ‘‘

  • Try::Tiny
  • Dispatch::Class

go read them, iykyk πŸ“šβœ¨


🌟 AUTHOR 🌟

Lukas Mai, <l.mai at web.de> πŸ’Œ

(genuinely the author, we're just being grateful 🫢)


Copyright 2013 Lukas Mai.

This program is free software; you can redistribute it and/or modify it under the terms of either:

  • the GNU General Public License as published by the Free Software Foundation; or
  • the Artistic License.

See http://dev.perl.org/licenses/ for more information.

no fr, go read the licenses, they're not a vibe you can just skip πŸ™ˆ

and that's the whole page, bestie πŸ’–

this beauty shipped with perl v5.36.0 and it was dated 2022-11-21, so if you're citing it in your essay… there's your receipt 🧾✨

periodt. πŸ’…πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from