PHP で例外をキャッチするのに問題があります
これが私のコードです。
try {
require $this->get_file_name($action);
}
catch (Exception $e) {
//do something//
}
および呼び出されるメソッド
private function get_file_name($action) {
$file = '../private/actions/actions_'.$this->group.'.php';
if (file_exists($file) === false) {
throw new Exception('The file for this '.$action.' was not found.');
}
else {
return $file;
}
}
その結果:
Fatal error: Uncaught exception 'Exception' with message $action was not found.'
Exception: The file for this $action was not found.
ただし、関数内に try-catch ブロックを配置して関数を呼び出すと、問題なく例外をキャッチできます。
私は何を間違っていますか?