Home  >  Article  >  Backend Development  >  The specific usage of try{} and catch{} in PHP

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

小云云
小云云Original
2018-03-21 11:34:371674browse

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();   
}   
 ?>

Related recommendations:

Detailed explanation of the specific usage of try{}catch{} in PHP_PHP tutorial

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

Statement:
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