Creates new DateTimeZone object and catch errors in PHP
Description
The following code shows how to creates new DateTimeZone object and catch errors.
Example
//w w w .j a v a2s . com
<?php
// Error handling by catching exceptions
$timezones = array('Europe/London', 'Mars/Phobos', 'Jupiter/Europa');
foreach ($timezones as $tz) {
try {
$mars = new DateTimeZone($tz);
} catch(Exception $e) {
echo $e->getMessage() . '<br />';
}
}
?>
The code above generates the following result.