Skip to content

Instantly share code, notes, and snippets.

@mia-0032
Last active December 10, 2015 03:28
Show Gist options
  • Save mia-0032/4374687 to your computer and use it in GitHub Desktop.
Save mia-0032/4374687 to your computer and use it in GitHub Desktop.
file_get_contentsでException飛ばすメモ
<?php
try {
ob_start();
//warningが出るコード
$file = file_get_contents('./not_found_file.txt');
$warning = ob_get_contents();
ob_end_clean();
//Warningがあれば例外を投げる
if ($warning) {
throw new Exception($warning);
}
} catch (Exception $e) {
header("HTTP/1.0 500 Internal Server Error");
echo 'エラーが発生しました。<br>';
echo 'メッセージ:' . $e->getMessage() . '<br>';
echo '発生箇所:' . $e->getFile() . ' 行:' . $e->getLine() . '<br>';
echo 'デバッグ:' . '<br>';
echo $e->getTraceAsString() . '<br>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment