Php Exception Handling

Source: Internet
Author: User
Tags php exception handling
{Code...} php is a weak type language. Why should Exception $ e be written in catch instead of $ e?

  1) {throw new Exception ("Value must be 1 or below");} return true;} // trigger an Exception in the "try" code block try {checkNum (2 ); // If the exception is thrown, this text will not be shown echo 'If you see this, the number is 1 or below ';} // catch Exception catch (** Exception $ e **) {echo 'message :'. $ e-> getMessage () ;}?>

Php is a weak type language. Why should Exception $ e be written in catch instead of $ e?

Reply content:

  1) {throw new Exception ("Value must be 1 or below");} return true;} // trigger an Exception in the "try" code block try {checkNum (2 ); // If the exception is thrown, this text will not be shown echo 'If you see this, the number is 1 or below ';} // catch Exception catch (** Exception $ e **) {echo 'message :'. $ e-> getMessage () ;}?>

Php is a weak type language. Why should Exception $ e be written in catch instead of $ e?

The exception is based on the type.

Type constraints on function parameters starting with PHP5: http://php.net/manual/zh/language.oop5.typehinting.php


  Var;}/*** another test function * The first parameter must be an array */public function test_array (array $ input_array) {print_r ($ input_array );}} // another class OtherClass {public $ var = 'Hello world ';}

Only objects and arrays (after php 5.1) are supported. Integer and string types are not supported.

Yes, it's a bit like java

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.