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 different string manipulation operators in perl?
Explain the arguments for perl interpreter.
How do I sort a hash by the hash key?
Which functions in perl allows you to include a module file.
How we can navigate the xml documents?
What exactly is grooving and shortening of the array?
How many types of variable in perl?
Explain strftime() function in perl?
Can inheritance be used in perl? Explain with the help of an example.
Explain regular expression in perl?
What are the various flags/arguments that can be used while executing a perl program?
What is perl I used for?
What is use of ‘->’ symbol?
explain the various functions/directives in perl that allow you to include/import a module. Also, state the differences between them.
How to create a directory in perl?