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
Explain ivalue in perl?
What are perl variables?
Does Perl have objects? If yes, then does it force you to use objects? If no, then why?
Explain about typeglobs?
How to open and read data files with Perl
Explain the various characteristics of perl.
What are the steps involved when the cgi program starts running?
What is the use of '>>' in perl?
Perl regular expressions are greedy" what does this mean?
Differentiate between arrays and list in perl.
How do I read command-line arguments with Perl?
What is the difference between perl array and perl hash?
How to sort arrays in perl?
what are the three groups involved in information sharing?
Differences between die and exit.