|
NAMETry::Catch - Try Catch exception handler based on Try::Tiny But fasterSYNOPSISuse Try::Catch; try { die "something went wrong"; } catch { } finally { ##some cleanup code }; ##<--- semi colon is required. DESCRIPTIONA small, fast, try catch blocks for perl, it's inspired and mostly copied from Try::Tiny but with some modifications to boost execution speed, see "Benchmarks".I published a new module instead of contributing to Try::Tiny directly because I had to break some features available in Try::Tiny some to boost speed and some because I didn't like. Differences
CAVEATSSame as "CAVEATS" in Try::TinyBenchmarksThis is not totally fair but please consider Try::Catch a stripped Try::Tiny version with no blessing and no usage of Sub::Name, so it must be faster, right! :)This is a simple test with just a try catch blocks with no exception | Module: | Rate | % | |-------------------------------------------| | Try::Tiny | 98425/s | -68% | | Try::Catch | 304878/s | 210% | Test with Try Catch, Finally Blocks, No Exception | Module: | Rate | % | |-------------------------------------------| | Try::Tiny | 60423/s | -75% | | Try::Catch | 245700/s | 304% | Test with Try, Catch, Finally Blocks, AND Exception | Module: | Rate | % | |-------------------------------------------| | Try::Tiny | 41288/s | -65% | | Try::Catch | 116414/s | 182% | I've also tested against TryCatch and the results were good, considering that TryCatch is an XS module | Module: | timing 500000 iterations | |----------------------------------------------------------------------- | | TryCatch | 1 secs (0.58 usr + 0.00 sys = 0.58 CPU) @ 865051.90/s | | Try::Catch | 2 secs (1.73 usr + 0.00 sys = 1.73 CPU) @ 288350.63/s | | Try::Tiny | 6 secs (6.16 usr + 0.02 sys = 6.17 CPU) @ 81011.02/s | Benchmarks included in this dist inside bench folder See Also
Known BugsWhen doing block jump from try { } or catch { } then finally will not be called.For example use Try::Catch; for (1) { try { die; } catch { goto skip; } finally { #finally will not be called print "finally was called\n"; } } skip: finally will work in most cases unless there is a block jump (last, goto, exit, ..) so I recommend avoid using finally at all as it's planned to be removed in v2.0.0 AUTHORMamod A. Mehyar, <mamod.mehyar@gmail.com>LICENSEThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself
Visit the GSP FreeBSD Man Page Interface. |