I am using Try::Tiny for try-catch.
Code goes as below:
use Try::Tiny;
try {
print "In try";
wrongsubroutine(); # undefined subroutine
}
catch {
print "In catch";
}
somefunction();
...
sub somefunction {
print "somefunction";
}
When I execute It comes like this:
somefunction
In Try
In catch
The output sequence looks wrong to me. Is it wrong? or Is this normal behavior?
Just like forgetting a semi-colon in
causes the output
somefunctionto be passed toprintinstead of$_, a missing semi-colon is causing the output ofsomefunctionto be passed as an argument tocatch.tryandcatchare subroutines with the&@prototype. That meansis the same as
So your code is the same as
As you can see, the missing semi-colon after the
catchblock is causingsomefunctionto be called beforecatch(which returns an object that tellstrywhat to do on exception) andtry.The code should be
which is achieved by placing a semi-colon after the try-catch call.