How would you trap error occurred in the perl program/file?
Answer Posted / prabhath kota
You can catch the errros by using eval function.
Keep your code in eval block some thing like shown below.
Eg.,
#################################
eval {
my $a = 0;
my $b = $a/0; #Dividing 0 with 0 is definitely an error
};
if ($@) {
print "\n Error in your code";
}
############################
-> Eval block always ends with a semi-colon. $@ will catch
the errors persent.
-> If any errors are present $@ will be set otherwise $@
will not be set
-> Unfortunately in Perl we don't have Explicit Error
handling techniques like some other languages like java etc
I mean like IOException etc.,
Is This Answer Correct ? | 5 Yes | 3 No |
Post New Answer View All Answers
What are the features of perl language?
You want to concatenate strings with perl. How would you do that?
How can you define “my” variables scope in Perl and how it is different from “local” variable scope?
Explain perl. What are the advantages of programming in perl?
Explain goto label?
How do you set environment variables in perl?
What does `$result = f() .. g()' really return?
What is an interpolation in perl?
How does a “grep” function perform?
Write an example explaining the use of symbol tables.
What does undef function in perl?
What can be done for efficient parameter passing in perl? Explain.
Explain what is STDIN, STDOUT and STDERR?
Assuming both a local($var) and a my($var) exist, what's the difference between ${var} and ${"var"}?
What does a die() function do in perl?