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
List the files in current directory sorted by size ?
What is 'rollback' command in perl?
What value is returned by a lone `return;’ statement?
In Perl we can show the warnings using some options in order to reduce or avoid the errors. What are that options?
List the data types that Perl can handle?
How to deleting an existing file in perl programming?
How to open and read data files with Perl
What is the use of -n and -p options?
How to code in perl to implement the tail function in unix?
Explain lists and ivalue?
What is grep used for in perl?
What is -> symbol in perl?
What is perl push array function?
How can you replace the characters from a string and save the number of replacements?
What are the logical operators used for small scale operations? Explain them briefly.