Kohana 3.3: How to handle call forwarding inside Try ... Catch blocks

New in KO 3.3 is the HTTP :: redirect method, which works by throwing an HTTP_Exception_302 that bubbles up and is processed by the system for the actual redirect.

My question is: how can I do a redirect without catching its exception if I call a redirect in a try...catch ?

eg:.

 try { if($var === TRUE){ HTTP::redirect(URL::site($_REQUEST['redirect_uri'])); }else{ throw new Exception('Error'); } } catch(Exception $e) { $this->template->errors[] = $e->getMessage(); } 

This will not result in a redirect, because a generic Exception handler will catch it. How can I avoid this?

+4
source share
2 answers
 try { if($var === TRUE){ HTTP::redirect(URL::site($_REQUEST['redirect_uri'])); }else{ throw new Exception('Error'); } } catch(HTTP_Exception_Redirect $e) { // just rethrow it throw $e; } catch(Exception $e) { $this->template->errors[] = $e->getMessage(); } 
+3
source

Do not be so liberal in your choice of exceptions. Catch what you expect and nothing more. This problem should not exist.

+1
source

All Articles