Exceptions - this is the only thing you do not understand IMHO: exceptions are designed to get out of your control, should be caught if they are considered from outside the limits into which they fell. The try block has a certain limit: it must contain related actions. For example, take a catch try block:
$array = array();
try {
} catch (...) {
$array[0]['default'] = 'me';
$array[0]['default2'] = ...;
...
}
, try. , , . , , . - , $, : , , .
, :
$array = array();
try {
if (!file_exists('file.php')) throw new Exception('file does not exists');
include('file.php');
} catch (Exception $e) {
trigger_error($e->getMessage());
}
. :
if (!file_exists('file.php')) trigger_error('file does not exists');
include('file.php');