How would you trap error occurred in the perl program/file?

Answer Posted / shah faisal

#Ist trapping the error in a block
eval {
# perl code goes here
};

if ($@) { # $@ is a special variable containing the error
if any else blank
print "Print your own error If u want";
}

# 2nd
# use if or unless for a loop ;ike below
if(chk some condition)
{
die"$!\n"; # if the condition success
}
system generated error is printed and the scirpt is exited
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What package you use to create a windows services?

556


Define say() function in perl?

613


You want to connect to sql server through perl. How would you do that?

611


Show the use of sockets for the server and client side of a conversation?

552


There are some duplicate entries in an array and you want to remove them. How would you do that?

579






You want to read command-line arguements with perl. How would you do that?

572


Explain returning values from subroutines?

593


Which has the highest precedence, List or Terms? Explain?

575


How do you find the length of an array?

645


How do you set environment variables in perl?

625


Comment on the scope of variables in perl.

598


what is the main function of fork() in cgi programming?

638


Write syntax to add two arrays together in perl?

620


How to convert arrays into a string in perl?

587


How to print escaping characters inside a string in perl?

604