I am trying to figure out why that error is thrown here. Shouldn't it just print 0 provided something wrong happens inside the try block and print 10 otherwise ?
#!/usr/bin/perl
use 5.006;
use strict;
use warnings;
use Try::Tiny;
my $test = 0;
try{
$test = 10;
my $s = $test /2;
}
catch{
print $_;
}
print $test;
You are missing a ; after the try/catch "statement"; your code is passing the result of the print $test
as an extra parameter to catch where it is expecting a finally clause and dies before it even gets into the try block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With