Home  >  Article  >  Web Front-end  >  Detailed explanation of the usage of try{} and catch{} in PHP

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

小云云
小云云Original
2018-03-30 14:12:501256browse

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:

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!

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