Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

What is the use of 'ne' operator?

1051


What are the steps involved in configuring a server using cgi programming?

937


Define dynamic scoping.

933


Explain perl one-liner?

997


Explain about the applications of perl?

1016


Write syntax to use grep function?

1015


What is v-strings?

1139


How to read a single line from a file in perl?

1013


How to deleting an existing file in perl programming?

949


What's the difference between /^Foo/s and /^Foo/?

1261


Explain which feature of PERL provides code reusability?

1269


What are the logical operators used for small scale operations?

1002


You want to empty an array. How would you do that?

961


When would `local $_' in a function ruin your day?

999


Explain gmtime() function in perl?

1020