[Solar-talk] Handling exceptions

Jeff Surgeson solar at 3hex.com
Fri Apr 18 13:51:47 CDT 2008


Hi All

Is this the correct way to go about handling exceptions/overriding default 
exceptions.

I have a image upload app that currently uses Lux_Filesytem_Upload to handle 
image uploads.

When Lux throws an exception on ERR_FILE_SIZE or one of the other possible 
upload errors the exception will be handled by the default 
_exceptionDuringFetch(Exception $e) method and the default exception view in 
Solar, which is great but not what you want to display to the user.

So for example when a file is too large I want to tell the user that is the 
case and not all the related exception information etc. So I  have overridden 
_exceptionDuringFetch(Exception $e) in my image app with the following to 
extract the local message and show it in a exception view.

(Just a hack of the default soalr stuff)

protected function _exceptionDuringFetch(Exception $e)
{
        $message = $e->getMessage();
        $this->errors[] = $message;
        $this->_view = 'exception';
        $this->_render();
        return $this->_response;
} 

And in my exception view

<?php
    foreach ((array) $this->errors as $err) {
        echo "<li>";
        echo $this->getText($err);
        echo "</li>\n";
    }
?>

Is this the correct way to be handling exceptions thrown by other vendor 
classes? or is there a more elegant or correct way to be doing it?

-- 
...........::::::...........
Jeff Surgeson / South Africa


More information about the Solar-talk mailing list