title: Codeigniter 3 show_404 function issue - MY_Exception doesn't load
body: <p>I'm using Codeigniter 3 and I want to custom the show_404() function.</p>
  
  <p>Here is my main controller:</p>
  
  <p>
  
  <pre><code>class Welcome extends CI_Controller {
  
      public function index() {
          $this-&gt;load-&gt;view('welcome_message');
      }
  
      public function otherMethod() {
          show_404();
      }
  
  }
  </code></pre>
  
  <p>Added on my routes.php</p>
  
  <pre><code>$route['404_override'] = 'error/show_404_custom';
  </code></pre>
  
  <p>Created the controller Error.php with the method show_404_custom</p>
  
  <pre><code>&lt;?php
  defined('BASEPATH') OR exit('No direct script access allowed');
  
  class Error extends CI_Controller {
  
      public function show_404_custom() {
          $this-&gt;load-&gt;view('404_read_view');
      }
  }
  </code></pre>
  
  <p>The 404_read_view.php view:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;p&gt;Custom 404 page.&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Then I've tested with some undefined URL like:  </p>
  
  <pre><code>/index.php/welcome/method_A 
  </code></pre>
  
  <p>And I successfully get my Custom 404 page.</p>
  
  <p>However, if I run a method that uses the <code>show_404()</code> function like:  </p>
  
  <pre><code>/index.php/welcome/otherMethod 
  </code></pre>
  
  <p>I oddly get the standard Codeigniter 404 page.</p>
  
  <p>I've searched a bit and found out that I should Extend the Exception core class and override the show_404() function like this:<br>
  <a href="https://stackoverflow.com/a/8425433/4301970">https://stackoverflow.com/a/8425433/4301970</a></p>
  
  <p>So, I created the MY_Exceptions.php class inside /application/core:</p>
  
  <pre><code>&lt;?php (defined('BASEPATH')) OR exit('No direct script access allowed');
  
  class MY_Exceptions extends CI_Exceptions {
  
      public function __construct() {
          parent::__construct();
      }
  
  
      public function show_404() {
          $CI =&amp; get_instance();
          $CI-&gt;load-&gt;view('404_read_view');
          echo $CI-&gt;output-&gt;get_output();
          exit;
      }
  
  }
  </code></pre>
  
  <p>And when I run the URL:  </p>
  
  <pre><code>/index.php/welcome/otherMethod 
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>Fatal error: Class 'MY_Exceptions' not found in (...)\system\core\Common.php on line 196
  </code></pre>
  
  <p>I took look inside Common.php and noticed that the load class function looks inside the libraries directory instead of core directory?</p>
  
  <pre><code>function &amp;load_class($class, $directory = 'libraries', $param = NULL)
  </code></pre>
  
  <p>How can I solve this problem?</p>