Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For my projects I never specified any specific separated route for 404. I just catch exceptions thrown by routing, when no appropriate route was found.</p> <p>Here is how I am handling all kind of exceptions that I've discovered in Kohana. I hope it will help you.</p> <pre><code>try { try { $request = Request::instance(); $request-&gt;execute(); } catch (ReflectionException $e) { Kohana::$log-&gt;add(Kohana::ERROR_404, Kohana::exception_text($e)); if (!IN_PRODUCTION) { throw $e; } $request-&gt;response = Request::factory('err/404')-&gt;execute(); } catch (Exception404 $e) { Kohana::$log-&gt;add(Kohana::ERROR_404, Kohana::exception_text($e)); if (!IN_PRODUCTION) { throw $e; } $request-&gt;response = Request::factory('err/404')-&gt;execute(); } catch (Kohana_Request_Exception $e) { Kohana::$log-&gt;add(Kohana::ERROR_404, Kohana::exception_text($e)); if (!IN_PRODUCTION) { throw $e; } header('Content-Type: text/html; charset='.Kohana::$charset, TRUE, 404); echo Request::factory('err/404')-&gt;send_headers()-&gt;execute()-&gt;response; exit; } catch (exception $e) { Kohana::$log-&gt;add(Kohana::ERROR, Kohana::exception_text($e)); if (!IN_PRODUCTION) { throw $e; } $request-&gt;status = 500; $request-&gt;response = Request::factory('err/500')-&gt;execute(); } } catch (exception $e) { if (!IN_PRODUCTION) { throw $e; } echo '&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"/&gt; &lt;/head&gt; &lt;body&gt; here is the message that everything is veeeery bad &lt;/body&gt; &lt;/html&gt;'; exit; } </code></pre> <p>Exception404:</p> <pre><code>class Kohana_Exception404 extends Kohana_Exception { public function __construct($message = 'error 404', array $variables = NULL, $code = 0) { parent::__construct($message, $variables, $code); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload