1
是否有PHP任何方式來分割在兩個不同的try
和catch
「包含文件」,將在一個文件中try
和另一個catch
?拆分嘗試和catch異常包括文件
喜歡的東西:
<?php
include('begin_try.php');
...
//some code goes here
...
include('end_try_and_catch_exceptions.php');
?>
//文件名:begin_try.php:
<?php
header('Content-type: application/json');
try {
?>
//文件名:end_try_and_catch_exceptions.php:
<?php
} catch (Exception $e) {
echo json_encode(array(
'error' => array(
'code' => $e->getCode(),
'message' => $e->getMessage()
)
));
}
?>
由於沒有人提供更好的想法,我會將您的答案標記爲正確答案。 – Kainax 2015-07-12 07:49:25