Sunday 15 July 2012

php - Cannot catch Laravel 4 exception -



php - Cannot catch Laravel 4 exception -

i'm trying grab laravel exception within library.

namespace marsvin\output\joomlazoo; class compiler { protected function compileitem($itemid, $item) { $boom = explode('_', $itemid); $boom[0][0] = strtoupper($boom[0][0]); $classname = __namespace__."\\compiler\\".$boom[0]; seek { $class = new $classname(); // <-- line 38 } catch(\symfony\component\debug\exception\fatalerrorexception $e) { throw new \exception('i\'m not beingness thrown!'); } } }

this exception i'm getting:

file: "c:\mamp\htdocs\name\app\libraries\webname\output\joomlazoo\compiler.php" line: 38 message: "class 'marsvin\output\joomlazoo\compiler\deas' not found" type: "symfony\component\debug\exception\fatalerrorexception"

the name of class voluntarily wrong.

edit 1:

i noticed if throw exception within try statement can grab exception:

try { throw new \exception('i\'d thrown!'); } catch(\exception $e) { throw new \exception('i\'m overriding previous exception!'); // beingness thrown }

the problem you're trying grab fatalerrorexception in class, laravel won't allow fatal error there; terminates immediately. if trying grab different kind of exception, code work fine.

you can grab , handle fatal errors app::fatal method in app/start/global.php, won't help deal exception within library, or handle specificity. improve alternative trigger "catchable" exception (something illuminate, instance), or throw custom 1 based on status trying check.

in case, if goal deal undefined classes, here's suggest:

try { $classname = 'badclass'; if (!class_exists($classname)) { throw new \exception('the class '.$classname.' not exist.'); } // a-ok... $class = new $classname(); } catch( exception $e) { // handle error, and/or throw different exception throw new \exception($e->getmessage()); }

php laravel-4

No comments:

Post a Comment