Cakephp-errors-exception-handling
提供:Dev Guides
CakePHP-エラーと例外処理
システムの障害は、システムの円滑な実行のために効果的に処理される必要があります。 CakePHPには、発生したエラーを出力して記録するデフォルトのエラートラップが付属しています。 この同じエラーハンドラを使用して、*例外*をキャッチします。 デバッグがtrueの場合、エラーハンドラーはエラーを表示し、debugがfalseの場合、エラーをログに記録します。 CakePHPには多数の例外クラスがあり、組み込みの例外処理により、キャッチされなかった例外をキャプチャし、有用なページをレンダリングします。
エラーと例外の構成
エラーと例外はファイル config \ app.php で設定できます。 エラー処理は、アプリケーションのエラー処理を調整できるいくつかのオプションを受け入れます-
Option | Data Type | Description |
---|---|---|
errorLevel | int | The level of errors you are interested in capturing. Use the built-in php error constants, and bitmasks to select the level of error you are interested in. |
trace | bool | Include stack traces for errors in log files. Stack traces will be included in the log after each error. This is helpful for finding where/when errors are being raised. |
exceptionRenderer | string | The class responsible for rendering uncaught exceptions. If you choose a custom *class, you should place the file for that class in src/Error*. This class needs to implement a *render() *method. |
log | bool | When true, exceptions + their stack traces will be logged to* Cake\Log\Log*. |
skipLog | array | An array of exception classnames that should not be logged. This is useful to remove NotFoundExceptions or other common, but uninteresting logs messages. |
extraFatalErrorMemory | int | Set to the number of megabytes to increase the memory limit by when a fatal error is encountered. This allows breathing room to complete logging or error handling. |
例
次のコードに示すように、 config/routes.php ファイルに変更を加えます。
次のURLにアクセスして、上記の例を実行します。
出力
実行すると、次の出力が表示されます。