B
Bpejman
Hi Everyone,
Can someone please shed some light on this Try and Catch issue that
I'm running into? I would highly appreciate any help and/or
guidance. I've researched the web thoroughly and still no luck. I
need to know exactly what libs I need to import into my program to be
able to do the below statement (as done similarly in Python).
sub foo {
try {
assert (0);
} catch {
print "Caught assertion error\n";
};
}
Now, I've used all of the below libraries but unfortunately
"assert(0);" does not jump into the catch {} scope. It simply exists
the program from there where in other languages, assert always raises
an exception which is caught by except{} or catch{} statement.
use Carp::Assert;
use Test::Harness::Assert;
use Error;
I do not want to use Eval and if ($@) since I cannot return any values
from within Eval. For example, the following will not work for me:
print foo(); #does not print any of the return codes from function
foo since they reside within the eval.
sub foo {
eval {
assert (1);
return 1;
};
if ($@) {
print "oops";
return 0;
}
}
Thanks everyone!!!
Bobby
Can someone please shed some light on this Try and Catch issue that
I'm running into? I would highly appreciate any help and/or
guidance. I've researched the web thoroughly and still no luck. I
need to know exactly what libs I need to import into my program to be
able to do the below statement (as done similarly in Python).
sub foo {
try {
assert (0);
} catch {
print "Caught assertion error\n";
};
}
Now, I've used all of the below libraries but unfortunately
"assert(0);" does not jump into the catch {} scope. It simply exists
the program from there where in other languages, assert always raises
an exception which is caught by except{} or catch{} statement.
use Carp::Assert;
use Test::Harness::Assert;
use Error;
I do not want to use Eval and if ($@) since I cannot return any values
from within Eval. For example, the following will not work for me:
print foo(); #does not print any of the return codes from function
foo since they reside within the eval.
sub foo {
eval {
assert (1);
return 1;
};
if ($@) {
print "oops";
return 0;
}
}
Thanks everyone!!!
Bobby