TEST2::TOOLS::EXCEPTION(3pm)

🌸 NAME 🌸

Test2::Tools::Exception β€” Test2 based tools for checking exceptions. This is the Test2::Tools::Exception(3pm) manual page, bestie, and it's lowkey iconic ✨

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so this is the Test2 implementation of code used to test exceptions. It's similar to Test::Fatal, but it intentionally does much less β€” no cap, that's the whole point, and it's giving focused main character energy πŸ’…

✨ SYNOPSIS ✨

use Test2::Tools::Exception qw/dies lives/;

like(
    dies { die 'xxx' },
    qr/xxx/,
    "Got exception"
);

ok(lives { ... }, "did not die") or note($@);

πŸ’… EXPORTS πŸ’…

All subs are exported by default β€” every single one, no extra import drama 🫢

  • $e = dies { ... } β€” This traps any exception the codeblock throws. If no exception is thrown, the sub returns undef. If an exception is thrown, it gets returned. This function preserves $@; it will not be altered from its value before the sub is called. Periodt πŸ’–
  • $bool = lives { ... } β€” This traps any exception thrown in the codeblock. It returns true when there is no exception, and false when there is. $@ is preserved from before the sub is called when there is no exception. When an exception is trapped, $@ will have the exception so you can look at it πŸ‘€
  • $bool = try_ok { ... }
  • $bool = try_ok { ... } "Test Description" β€” This runs the code block, trapping any exception. If there is no exception, a passing event will be issued. If the test fails, a failing event will be issued, and the exception will be reported as diagnostics.
Note: This function does not preserve $@ on failure. It will be set to the exception the codeblock throws. This is by design so that you can obtain the exception if desired 😌

πŸŽ€ DIFFERENCES FROM TEST::FATAL πŸŽ€

So Test::Fatal sets $Test::Builder::Level such that failing tests inside the exception block will report to the line where exception() is called. The author is like, "I disagree with this," and thinks the actual line of the failing test is more important. Ultimately, though, Test::Fatal cannot be changed, and people probably already depend on that behavior. It's giving legacy lore πŸ’€

πŸ”₯ SOURCE πŸ”₯

The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. Go peek, bestie πŸ¦‹

πŸ‘‘ MAINTAINERS πŸ‘‘

Chad Granum <exodist@cpan.org>

🧚 AUTHORS 🧚

Chad Granum <exodist@cpan.org>

Copyright Chad Granum <exodist@cpan.org>.

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

See http://dev.perl.org/licenses/


okay bye bestie 🫢 β€” this iconic lil page comes from perl v5.42.3, dated 2026-11-03, and the manual is Test2::...xception(3pm) βœ¨πŸ’–

πŸ“¦ where this page comes from