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

How can you use Perl warnings and what is the importance to use them?

531


How do I do fill_in_the_blank for each file in a directory?

539


Write syntax to use grep function?

544


What $! In perl?

519


How to code in perl to implement the tail function in unix?

519






How to check the status of airplane mode (enable/disable) in perl for Android mobile?

2604


Explain the meaning of subroutine?

504


Explain which feature of PERL provides code reusability?

720


What is q (single q) operator in perl?

526


How can information be put into hashes?

525


What are the various uses of perl?

516


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

532


What are the different string manipulation operators in perl?

522


What is posix in perl?

514


What is subroutine in perl?

520