mirror of
https://github.com/php/php-src.git
synced 2026-04-09 09:03:04 +02:00
Update Exceptions example.
This commit is contained in:
@@ -47,22 +47,37 @@ Changes in the Zend Engine 2.0
|
||||
|
||||
Example
|
||||
|
||||
try {
|
||||
code
|
||||
<?php
|
||||
class MyException {
|
||||
function MyException($_error) {
|
||||
$this->error = $_error;
|
||||
}
|
||||
|
||||
if (failure) {
|
||||
throw new MyException(Failure);
|
||||
function getException() {
|
||||
return $this->error;
|
||||
}
|
||||
}
|
||||
|
||||
code
|
||||
} catch ($exception) {
|
||||
handle exception
|
||||
function ThrowException() {
|
||||
throw new MyException("'This is an exception!'");
|
||||
}
|
||||
|
||||
throw $exception; // Re-throw exception.
|
||||
}
|
||||
try {
|
||||
} catch ($exception) {
|
||||
print "There was an exception: " . $exception->getException();
|
||||
print "\n";
|
||||
}
|
||||
|
||||
Old code that does not use exceptions will run without
|
||||
modifications.
|
||||
try {
|
||||
ThrowException();
|
||||
} catch ($exception) {
|
||||
print "There was an exception: " . $exception->getException();
|
||||
print "\n";
|
||||
}
|
||||
?>
|
||||
|
||||
Old code that does not define user-space functions 'catch',
|
||||
'throw' and 'try' will run without modifications.
|
||||
|
||||
* Namespaces.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user