Params...eptions(3pm)

πŸ“¦
version 1.20 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

okay so welcome to Params::CallbackRequest::Exceptions β€” that's the Params...eptions(3pm) page, aka the User Contributed Perl Documentation for the exception definitions that Params::CallbackRequest and Params::Callback throw around. bestie, it's literally just the exception classes. that's the whole vibe. πŸŽ€


🌸 SYNOPSIS 🌸

use Params::CallbackRequest::Exceptions;
Params::Callback::Exception::Execution->throw("Whoops!");

use Params::CallbackRequest::Exceptions abbr => [qw(throw_cb_exec)];
throw_cb_exec "Whoops!";

look at that. two ways to say "Whoops!" and both of them slay. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so this module is where the exceptions used by Params::CallbackRequest and Params::Callback get created. that's its whole job, no cap.

those exceptions are subclasses of Exception::Class::Base, and they're built with the interface defined by Exception::Class. iconic inheritance moment fr fr. ✨


πŸ’– INTERFACE πŸ’–

🫢 Exported Functions

this module exports two functions by default. two. that's it. and they're both useful, so like, we stan.

  • isa_cb_exception

here's the whole vibe check:

eval { something_that_dies() };
if (my $err = $@) {
    if (isa_cb_exception($err, 'Abort')) {
        print "All hands abandon ship!";
    } elsif (isa_cb_exception($err)) {
        print "I recall an exceptional fault.";
    } else {
        print "No clue.";
    }
}

so this function takes one argument and returns true if that thing is a Params::Callback::Exception object. that's it, that's the function. πŸŽ€

you can also slide in a second, optional argument to point at one specific subclass of Params::Callback::Exception β€” like, "is this the Abort kind specifically, bestie?" and it'll tell you yes or no. ⭐

  • rethrow_exception

and here's the receipts:

eval { something_that_dies() };
if (my $err = $@) {
    # Do something intelligent, and then...
    rethrow_exception($err);
}

this one takes an exception as its sole argument and rethrows it. but the way it rethrows depends on what you handed it, and honestly the logic is giving tiered:

  • if the argument is an object that can('throw') β€” like, say, any subclass of Exception::Class β€” then rethrow_exception() calls its rethrow method. easy.
  • if not that, but the argument is a reference, then rethrow_exception() just plain dies with it. simple as.
  • and finally, if the argument isn't a reference at all, rethrow_exception() throws a brand new Params::Callback::Exception, using the argument as the exception error message. 🫢

🌈 Abbreviated Exception Functions

every single exception class made by Params::CallbackRequest::Exceptions has a functional alias for its throw class method. short king behavior.

to get them, you import an array reference of the abbreviated function names you want, passed through the abbr parameter:

use Params::CallbackRequest::Exceptions abbr => [qw(throw_cb_exec)];

and here are the names of all the abbreviated functions, no gatekeeping:

  • throw_cb β†’ Params::Callback::Exception
  • throw_bad_key β†’ Params::Callback::Exception::InvalidKey
  • throw_cb_exec β†’ Params::Callback::Exception::Execution
  • throw_bad_params β†’ Params::Callback::Exception::Params
  • throw_abort β†’ Params::Callback::Exception::Abort

πŸ‘‘ Exception Classes

the exception classes created by Params::Callback::Exception are as follows. get comfy, we're going through all of them:

  • Params::Callback::Exception

this is the base class for all the Params::Callback exception classes. its functional alias is throw_cb. the mother of the group chat, fr. πŸ’œ

  • Params::Callback::Exception::InvalidKey

Params::CallbackRequest throws this one when a callback key in the parameter hash passed to new() has no corresponding callback. like, you named a key and nothing answered. πŸ’€

on top of all the attributes offered by Exception::Class::Base, this class also has the attribute callback_key. use the callback_key() accessor to find out which callback key triggered the exception. detective work, but make it perl. πŸ•΅οΈ

Params::Callback::Exception::InvalidKey's functional alias is throw_bad_key.

  • Params::Callback::Exception::Execution

this is the exception thrown by Params::CallbackRequest's default exception handler when a callback subroutine or method dies. dramatic? yes. deserved? also yes. 😭

on top of the attributes offered by Exception::Class::Base, this class also has two attributes:

  • callback_key β€” the parameter key that triggered the callback
  • callback_error β€” the error thrown by the callback subroutine or method

Params::Callback::Exception::Execution's functional alias is throw_cb_exec.

  • Params::Callback::Exception::Params

thrown when an invalid parameter is passed to Params::CallbackRequest's or Params::Callback's new() constructors. it's the bouncer at the constructor door. πŸ™ˆ

its functional alias is throw_bad_params.

  • Params::Callback::Exception::Abort

thrown by Params::Callback's abort() method. the page also says, word for word, "functional alias is throw_cb" right there in this paragraph β€” yes, we noticed, and no, bestie, we are not editing it, we're just reporting what the doc says. πŸ‘€

on top of the attributes offered by Exception::Class::Base, this class also has the aborted_value attribute. use the aborted_value() accessor to see what value was passed to abort(). so you know exactly what got aborted. closure. πŸŽ€

Params::Callback::Exception::Abort's functional alias is throw_abort.


🌟 SEE ALSO 🌟

  • Params::Callback is the base class for all callback classes.
  • Params::CallbackRequest sets up callbacks for execution.
  • Exception::Class defines the interface for the exception classes created here.

three links, all essential, all linked into each other like the little ecosystem they are. iykyk. 🌈


πŸ’Œ SUPPORT πŸ’Œ

this module is stored in an open GitHub repository at <http://github.com/theory/params-callbackrequest/>. feel free to fork and contribute! bestie, the door is open, come through. 🫢

please file bug reports either via GitHub Issues at <http://github.com/theory/params-callbackrequest/issues/> or by sending mail to bug-params-callbackrequest@rt.cpan.org (that's <bug-params-callbackrequest@rt.cpan.org>). bugs deserve to be heard, periodt. πŸ›


⭐ AUTHOR ⭐

David E. Wheeler <david@justatheory.com> β€” thank you for your service, king. πŸ‘‘


Copyright 2003-2011 David E. Wheeler. Some Rights Reserved.

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

so yeah β€” free software, some rights reserved, same terms as Perl itself. legal but make it cute. πŸ’…

and that's the whole page, bestie!! this was Params...eptions(3pm), living under perl v5.36.0, dated 2022-10-15, in the fine tradition of User Contributed Perl Documentation. go forth and throw responsibly. mwah. πŸ’–βœ¨πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from