Note that there are some explanatory texts on larger screens.

plurals
  1. POI'm trying to handle an Exception in PHP but stack error is still showing rather than being handled by catch
    primarykey
    data
    text
    <p>I'm calling a method that I know could cause an error and I'm trying to handle the error by wrapping the code in a try/catch statement...</p> <p> <pre><code>class TestController extends Zend_Controller_Action { public function init() { // Anything here happens BEFORE the View has rendered } public function indexAction() { // Anything `echo`ed here is added to the end of the View $model = new Application_Model_Testing('Mark', 31); $this-&gt;view-&gt;sentence = $model-&gt;test(); $this-&gt;loadDataWhichCouldCauseError(); $this-&gt;loadView($model); // this method 'forwards' the Action onto another Controller } private function loadDataWhichCouldCauseError() { try { $test = new Application_Model_NonExistent(); } catch (Exception $e) { echo 'Handle the error'; } } private function loadView($model) { // Let's pretend we have loads of Models that require different Views switch (get_class($model)) { case 'Application_Model_Testing': // Controller's have a `_forward` method to pass the Action onto another Controller // The following line forwards to an `indexAction` within the `BlahController` // It also passes some data onto the `BlahController` $this-&gt;_forward('index', 'blah', null, array('data' =&gt; 'some data')); break; } } } </code></pre> <p>...but the problem I have is that the error isn't being handled. When viewing the application I get the following error...</p> <pre><code>( ! ) Fatal error: Class 'Application_Model_NonExistent' not found in /Library/WebServer/Documents/ZendTest/application/controllers/TestController.php on line 23 </code></pre> <p>Can any one explain why this is happening and how I can get it to work?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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