1
0
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:
Sebastian Bergmann
2001-12-29 08:17:57 +00:00
parent 9311e05119
commit 76cfd48f72

View File

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