Throwable(3)

okay so this is Throwable(3) from the User Contributed Perl Documentation, and if you're here bestie, it's giving β€œI am making exception objects and I want them to be cute and throwable.” valid. let's go πŸ’…

✨ NAME ✨

Throwable β€” a role for classes that can be thrown. that's it, that's the name section, no cap πŸŽ€

🌸 VERSION 🌸

version 1.001 β€” yes bestie, that's the version. periodt ✨

πŸ¦‹ SYNOPSIS πŸ¦‹

here's the vibe:

package Redirect;
# NOTE: Moo can also be used here instead of Moose
use Moose;
with 'Throwable';

has url => (is => 'ro');

then later, literally:

Redirect->throw({ url => $url });

πŸ’– DESCRIPTION πŸ’–

Throwable is a role for classes that are meant to be thrown as exceptions to standard program flow. it is very simple and does only two things: saves any previous value for $@ and calls die $self. iconic, lowkey minimal, obsessed.

Throwable is implemented with Moo, so you can stick to Moo or use Moose, as you prefer. choose your fighter 🫢

🐚 PERL VERSION 🐚

this library should run on perls released even a long time ago. it should work on any version of perl released in the last five years.

Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl. so like, the floor can move, bestie β€” that's the caveat 😭

πŸ’– ATTRIBUTES πŸ’–

previous_exception

This attribute is created automatically, and stores the value of $@ when the Throwable object is created. This is done on a best effort basis.

$@ is subject to lots of spooky action-at-a-distance. For now, there are clearly ways that the previous exception could be lost. bestie, it's best effort, not a blood oath πŸ’€

πŸŽ€ METHODS πŸŽ€

throw

Something::Throwable->throw({ attr => $value });

This method will call new, passing all arguments along to new, and will then use the created object as the only argument to die.

If called on an object that does Throwable, the object will be rethrown. slay, it knows how to rethrow itself πŸ‘‘

new_with_previous

die Something::Throwable->new_with_previous({ attr => $value });

Constructs an exception object and returns it, while trying to make sure that any values in $@ are safely stored in previous_exception without being stomped by evals in the construction process.

This is more reliable than calling new directly, but doesn't include the forced die in throw. so like, it protects the previous exception vibe but does not do the dramatic exit itself πŸ’…

πŸ‘‘ AUTHORS πŸ‘‘

  • Ricardo SIGNES <cpan@semiotic.systems> β€” author, absolute legend
  • Florian Ragwitz <rafl@debian.org> β€” author, also iconic

🌈 CONTRIBUTORS 🌈

  • Arthur Axel 'fREW' Schmidt <frioux@gmail.com> β€” contributor
  • Brian Manning <brian@xaoc.org> β€” contributor
  • Brian Manning <xaoc@cpan.org> β€” contributor
  • Christian Walde <walde.christian@googlemail.com> β€” contributor
  • Dagfinn Ilmari MannsΓ₯ker <ilmari@ilmari.org> β€” contributor
  • Dave Rolsky <autarch@urth.org> β€” contributor
  • David E. Wheeler <david@justatheory.com> β€” contributor
  • Graham Knop <haarg@haarg.org> β€” contributor
  • Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> β€” contributor
  • Justin Hunter <justin.d.hunter@gmail.com> β€” contributor
  • Matt S Trout <mst@shadowcat.co.uk> β€” contributor
  • Olaf Alders <olaf@wundersolutions.com> β€” contributor
  • Ricardo Signes <rjbs@semiotic.systems> β€” contributor
  • Toby Inkster <mail@tobyinkster.co.uk> β€” contributor

all of them ate, fr fr 🫢

This software is copyright (c) 2022 by Ricardo SIGNES.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


k that's the whole page, bestie πŸ’… β€” it's from perl v5.42.0, dated 2023-01-03, and the manual is Throwable(3). mwah 🫢✨

πŸ“¦ where this page comes from