PHPTry-catch statements, try-catch tips _ PHP Tutorial

Source: Internet
Author: User
Tags php try catch try catch
Tips for using PHPTry-catch statements and try-catch statements. Tips for using PHPTry-catch statements and PHPTry-catch statements to further handle exceptions, we need to use the try-catch statement-including the Try statement and at least one ca PHP Try-catch statement.

PHP Try-catch statement
To further handle exceptions, we need to use the try-catch statement-including the Try statement and at least one catch statement. Any code that calls a method that may throw an exception should use the try statement. Catch statements are used to handle exceptions that may be thrown. The following shows how to handle the Exception thrown by getCommandObject:

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

We can see that by combining the throw keyword with the try-catch statement, we can avoid the value returned by the error mark "pollution" class method. "Exception" is a built-in PHP type that is different from any other object and will not be confused.

If an exception is thrown, the script in the try statement stops execution and immediately redirects to the script in the catch statement.

If an exception is thrown but not captured, a fatal error occurs.

Articles you may be interested in:
  • Php Try Catch exception test
  • Detailed description of try catch exceptions in php

Http://www.bkjia.com/PHPjc/1104326.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1104326.htmlTechArticlePHP Try-catch statements use tips, try-catch use tips PHP Try-catch statements in order to further handle exceptions, we need to use the try-catch statement ---- including the Try statement and at least one ca...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.