Add error handling to basic example.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@299010 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Daniel Convissor 2010-05-05 03:45:09 +00:00
parent 87775dd402
commit 5da1c6eac5

View file

@ -94,7 +94,13 @@
<programlisting role="php">
<![CDATA[
<?php
$date = new DateTime('2000-01-01');
try {
$date = new DateTime('2000-01-01');
} catch (Exception $e) {
echo $e->getMessage();
exit(1);
}
echo $date->format('Y-m-d');
?>
]]>
@ -104,6 +110,14 @@ echo $date->format('Y-m-d');
<![CDATA[
<?php
$date = date_create('2000-01-01');
if (!$date) {
$e = date_get_last_errors();
foreach ($e['errors'] as $error) {
echo "$error\n";
}
exit(1);
}
echo date_format($date, 'Y-m-d');
?>
]]>