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 benefits of perl in using it as a web-based application?
How to get help for perl?
How to prevent file truncation in perl?
List all the features of perl programming?
What is a chop() function in perl?
What are the logical operators used for small scale operations?
How do you find the length of an array?
How to create a package?
Differentiate between arrays and list in perl.
What are the various uses of perl?
What is the use of command “use strict”?
Write an example explaining the use of symbol tables.
Explain use of ‘my’ keyword in perl?
What does init 5 and init 0 do?
Differentiate use and require?