How does PHP catch exceptions?

Source: Internet
Author: User
How does PHP catch exceptions?
Are there similar. NET Try catch mechanisms?
PHP does not have to debug the egg row by line!


Reply to discussion (solution)

Some have the same wording.
try {

} catch (Exception $e) {
Print $e->getmessage ();

}

Are there similar. NET Try catch mechanisms? This really has ~
PHP does not have to debug the egg row by line! Landlord did not find the IDE

In fact, PHP debugging can be adjusted at any time, where you want to tune, the simplest is where the output. Of course Zend-studio also provides a breakpoint function debugging, but far less convenient.
In fact, each has its own advantages, brother, or from the bar.

#1 Cute Arctic Bear Solution

try{$a = "SGFDFGDF"; $b = (int) $a; Echo ($b);} catch (Exception $e) {echo ("error". $e->getmessage ());//Here and the wood is executed AH}

You also need to throw an exception in the try{} statement block, throw new Exception (' It is a exception! '), and then capture by catch (Exception $e).

You also need to throw an exception in the try{} statement block, throw new Exception (' It is a exception! '), and then capture by catch (Exception $e). \
So I can catch it, but I have to specify the error message.
I want the wrong message, and I know it, and I'm catching a ghost.

Use Echo to find the anomaly, PHP can't.

Then go to see PHP error_log ah ... There will be a variety of detailed error messages .... What else can catch ...

Then go to see PHP error_log ah ... There will be a variety of detailed error messages .... What else can catch ...
Where does PHP's error_log look?

There are basically two types of errors, one that can be captured by PHP, such as syntax errors. There is also a logical error that the machine does not capture, so the try catch is used to capture the artifact.
I think you said the error is just the previous one, then open the error prompt display_errors = On, you can see.

and a set_exception_handle.

Your code is no exception, of course, will not execute that sentence

PHP Code

try{
$a = "SGFDFGDF";
$b = (int) $a;
Echo ($b);
}
catch (Exception $e) {
Echo ("Error". $e->getmessage ());//Here and the wood is executed.
}

Your code is no exception, of course, will not execute that sentence

Reference 5 Floor telankes2000 's reply:

PHP Code

try{
$a = "SGFDFGDF";
$b = (int) $a;
Echo ($b);
}
catch (Exception $e) {
Echo ("Error". $e->getmessage ());//Here and the wood is executed.
}
Shaping conversion Errors It's not a mistake.

This error system should be automatically captured.

Cough, this is not wrong, in PHP, automatic conversion

Reference 14 Floor Helloyou0 's reply:

Your code is no exception, of course, will not execute that sentence

Reference 5 Floor telankes2000 's reply:

PHP Code

try{
$a = "SGFDFGDF";
$b = (int) $a;
Echo ($b);
}
catch (Exception $e) {
Echo ("Error". $e->getmessage ());//Here and the wood is executed.
......

Shaping conversion Errors It's not a mistake. Coercion of type conversions is not an error in any language!
Although sometimes you don't get the results you expect.

PHP error exceptions are similar to Java, but they are usually thrown on their own: examples:
try{
$m = 0;
if ($m < 1) {
throw new Exception (' m= '. $m. ': Less than 0 ');
}
Echo $m;
} catch (Exception $e) {
echo "Error [line->". ( $e->getline ()). "]:". ($e->getmessage ());
}

PHP Weak type change data type no problem

Let the divisor be 0, and you'll see the throw anomaly.

I also have the same question.
For example, I used the $_get in PHP, but actually did not pass any GET parameters, this time will be wrong, I use try catch can not catch this error.
How can I know if get error and then handle it accordingly?

  • 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.