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 is the use of 'ne' operator?
What are the steps involved in configuring a server using cgi programming?
Define dynamic scoping.
Explain perl one-liner?
Explain about the applications of perl?
Write syntax to use grep function?
What is v-strings?
How to read a single line from a file in perl?
How to deleting an existing file in perl programming?
What's the difference between /^Foo/s and /^Foo/?
Explain which feature of PERL provides code reusability?
What are the logical operators used for small scale operations?
You want to empty an array. How would you do that?
When would `local $_' in a function ruin your day?
Explain gmtime() function in perl?