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
How to renaming a file in perl programming?
Which guidelines by Perl modules must be followed?
What are the reasons that cookie server can’t handle multiple connections?
What is the difference between single (') and double (") quote in a string in perl?
How to open a directory in perl?
How do I pass a command line argument in perl?
What can be done for efficient parameter passing in perl? Explain.
What is perl pop array function?
How can we create perl programs in unix, windows nt, macintosh and os/2 ?
How to access parameters passed to a subroutine in perl?
How to replace perl array elements?
Explain join function in perl?
How can I display all array element in which each element will display on next line in perl ?
Mention what is cpan?
What are the advantages of perl programming?