[Solar-talk] Handling exceptions

Antti Holvikari anttih at gmail.com
Fri Apr 18 14:38:30 CDT 2008


On Fri, Apr 18, 2008 at 9:51 PM, Jeff Surgeson <solar at 3hex.com> wrote:
> 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?

I think in this particular case you should just wrap those
Lux_Filesystem_Upload calls in try/catch and then display those as
feedback in the form. I designed Lux_Filesystem_Upload to be used like
that.

Usually, _exceptionDuringFetch() means that something is "terribly"
wrong, as in 505 wrong.

Ps. Paul has been doing work with form uploads and
Lux_Filesystem_Upload will probably be deprecated in favor of that new
functionality.

-- 
Antti Holvikari <http://anttih.com>


More information about the Solar-talk mailing list