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

Which functions in Perl allows you to include a module file or a module and what is the difference between them?

1010


How to connect to SQL server through Perl?

1054


Assuming both a local($var) and a my($var) exist, what's the difference between ${var} and ${"var"}?

986


We all know private variables exist in perl. But do private METHODS exist in perl ? Eg ?

2478


Define operators used in perl?

940


What is the closure in PERL?

1019


How do find the length of an array?

1134


What is the easiest way to download the contents of a URL with Perl?

954


How can you replace the characters from a string and save the number of replacements?

895


What are the logical operators used for small scale operations?

959


What are the various perl data types based on the context?

939


Explain the difference between die and exit in perl?

883


You want to download the contents of a url with perl. How would you do that?

875


There are two types of eval statements i.e. Eval expr and eval block. Explain them.

1034


How and what are closures implemented in perl?

890