Error::TypeTiny(3)

πŸ’– Error::TypeTiny πŸ’–

okay so bestie, this is the User Contributed Perl Documentation page for Error::TypeTiny β€” the module that makes Type::Tiny and all its little friends throw actual exception objects instead of just, like, yelling into the void. sit down, get comfy, we're doing this 🫢


✨ NAME ✨

Error::TypeTiny β€” exceptions for Type::Tiny and friends. it's giving "your type check failed but make it classy" πŸ’…


✨ SYNOPSIS ✨

look at her go πŸ¦‹

use feature 'try';
use Data::Dumper;
use Types::Standard qw( Str );

try {
   Str->assert_valid( undef );
}
catch ( $exception ) {
   warn "Encountered Error: $exception";
   warn Dumper( $exception->explain )
      if $exception->isa( "Error::TypeTiny::Assertion" );
}

✨ STATUS ✨

this module is covered by the Type-Tiny stability policy. so it's not gonna randomly ghost you, no cap πŸ‘‘


✨ DESCRIPTION ✨

when Type::Tiny and its related modules hit an error, they don't just die with some sad little string β€” nope, they throw an exception object. and every single one of those exception objects inherits from Error::TypeTiny. main character lineage fr fr 🌸

πŸŽ€ Constructors πŸŽ€

  • new(%attributes) β€” Moose-style constructor function. classic, iconic, does exactly what it says on the tin ✨
  • throw(%attributes) β€” constructs an exception and hands it straight to die. and the way that it automatically populates context and stack_trace if appropriate?? obsessed 😭
  • throw_cb($callback, %attributes) β€” constructs an exception and passes it to $callback, which should be a coderef. if it's undef, it just uses die instead. and yep, it also automatically populates context and stack_trace if appropriate πŸ’–

πŸŽ€ Attributes πŸŽ€

  • message β€” the error message. the what-went-wrong. the tea β˜•
  • context β€” a hashref holding the package, file and line that generated the error. receipts, basically 🧾
  • stack_trace β€” a more complete stack trace. heads up bestie: this feature requires Devel::StackTrace; use the $StackTrace package variable to switch it on. πŸ”₯

πŸŽ€ Methods πŸŽ€

  • to_string β€” returns the message, followed by the context if it is set. simple, clean, slay πŸ’…

πŸŽ€ Functions πŸŽ€

  • Error::TypeTiny::croak($format, @args) β€” functional-style shortcut to the throw method. takes an sprintf-style format string plus optional arguments to construct the message. πŸŽ€

πŸŽ€ Overloading πŸŽ€

  • Stringification is overloaded to call to_string. so when you stringify one of these bad boys, you get the nice message automatically. no extra steps, we love a convenience πŸ’œ

πŸŽ€ Package Variables πŸŽ€

  • %Carp::CarpInternal β€” Error::TypeTiny honours this package variable from Carp. (%Error::TypeTiny::CarpInternal is an alias for it.) 🌈
  • $Error::TypeTiny::StackTrace β€” boolean to toggle stack trace generation. flip it, girl πŸ”₯
  • $Error::TypeTiny::LastError β€” a reference to the last exception object thrown. your little keepsake of the most recent chaos πŸ’€

✨ CAVEATS ✨

okay so this is the part where we keep it real 🫢

even though Error::TypeTiny objects get thrown for errors produced by Type::Tiny, that does not mean every time you use Type::Tiny you'll get Error::TypeTinys whenever you want. sadly. 😭

for example: if you use a Type::Tiny type constraint in a Moose attribute, Moose will not call the constraint's assert_valid method (which is the one that throws an exception). instead it will call check and get_message (which do not throw), and will confess an error message of its own. rude, honestly. (but the $LastError package variable may save your bacon πŸ₯“ β€” so there's that.)


✨ BUGS ✨

please report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>. don't be shy, they wanna hear from you πŸ’Œ


✨ SEE ALSO ✨

  • Error::TypeTiny::Assertion
  • Error::TypeTiny::WrongNumberOfParameters
  • Try::Tiny
  • Try::Tiny::ByClass

the whole friend group, honestly πŸ‘―β™€οΈ


✨ AUTHOR ✨

Toby Inkster <tobyink@cpan.org>. king behavior πŸ‘‘


this software is copyright (c) 2013-2014, 2017-2025 by Toby Inkster.

this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. periodt. πŸ’…


✨ DISCLAIMER OF WARRANTIES ✨

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

(translation: no promises, bestie, it's all vibes and no guarantees πŸ™ˆ)


and that's the whole page, babe πŸ’– this one shipped as perl v5.42.0, dated 2026-01-17 β€” so you know it's fresh ✨ go forth and catch those exceptions, you've totally got this πŸ¦‹πŸŽ€

πŸ“¦ where this page comes from