Title. is Exception the role of a functioning domain? Or the language structure?
Reply content:
First of all it is very clear that try ... catch ... is a language structure.
That being the case, it is not possible to understand the Exception in parentheses after the catch with the function parameter type qualification.
If there is no Exception, such as writing:
<?phptry {} catch ($e) {}
You will get an error:
Parse error:parse error, expecting "identifier (t_string)" ' or "namespace (t_namespace)" ' or ' "\ \ (t_ns_separator)" ' in. ..
Obviously, the Exception here is an "expectation" for judging the type of exception caught.
If you use a class scenario to translate, it's probably similar to the following:
<?php$e = new Exception;if ($e instanceof Exception) { # do something ...}
If you are multiple catch, such as:
<?phptry { throw new customexception ("Error processing Request", 1),} catch (Customexception $e) { echo 1;} cat CH (Exception $e) { echo 2;} Class Customexception extends exception{}
Although the exception we throw is Exception, the catch catches to the first stop, so here it only outputs 1, if the interchange is the catch (CustomException $e)
catch (Exception $e)
same.
This is also the case with the following:
<?php$e = new Customexception;if ($e instanceof customexception) { echo 1;} elseif ($e instanceof Exception) { echo 2;} Class Customexception extends exception{}
You can see that java,exception is a class name, and the catch's $e is an instance of the class.
You can also write a class to inherit the exception, and then catch the catch.
Type Bar. You can also write your own exception class.
The above is exception handling-what does Exception in the catch (Exception $e) in PHP try Catch do? For more information, please pay attention to topic.alibabacloud.com (www.php.cn)!