Home > Web Front-end > JS Tutorial > body text

Detailed explanation of the usage of try{} and catch{} in PHP

小云云
Release: 2018-03-30 14:12:50
Original
1255 people have browsed it

try{}catch{} in PHP is exception handling. Put the code to be executed into the TRY block. If an exception occurs in a certain statement during the execution of these codes, the program jumps directly to the CATCH block, represented by $e Collect error information and display. Any code that calls a method that may throw an exception should use a try statement. The Catch statement is used to handle exceptions that may be thrown.

 < ?php   
 try {   
$mgr = new CommandManager();   
$cmd = $mgr->getCommandObject("realcommand");   
$cmd->execute();   
} catch (Exception $e) {   
print $e->getMessage();   
exit();   
}
Copy after login

Related recommendations:

The specific usage of try{} and catch{} in PHP

The above is the detailed content of Detailed explanation of the usage of try{} and catch{} in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!