Last active
December 10, 2015 03:28
-
-
Save mia-0032/4374687 to your computer and use it in GitHub Desktop.
file_get_contentsでException飛ばすメモ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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