Mailinglist Archive: yast-devel (81 mails)

< Previous Next >
Re: [yast-devel] About catching exceptions
  • From: Martin Vidner <mvidner@xxxxxxx>
  • Date: Thu, 22 Apr 2010 12:04:54 +0200
  • Message-id: <20100422100454.GB5014@xxxxxxxxxxxxxxxx>
On Thu, Apr 22, 2010 at 11:36:58AM +0200, Klaus Kaempf wrote:
when calling functions known to raise exceptions, its always good
practice to enclose calls with begin ... rescue ... end and catch
exceptions locally.

Good that you bring it up because I think that you got it absolutely
wrong.

Unless you give more specific examples, this only creates more
problems by bypassing the generic, well-thought out system-wide
recue from.

Your code will hide error details, or cause unnecessary code
duplication.

Catching exceptions should cover known problems (i.e. missing
permissions) as well as generic problems.

Example:


WRONG:

call_function_which_might_raise

CORRECT, unknown exceptions are handled by exception_trap in
http://gitorious.org/opensuse/yast-web-client/blobs/master/webclient/app/controllers/application_controller.rb

NOT ENOUGH:

begin
call_function_which_might_raise
rescue KnownException => e
handle_known_exception e
end

debatable

GOOD:

begin
call_function_which_might_raise
rescue KnownException => e
handle_known_exception e
rescue Exception => e
handle_generic_exception e
end

WRONG, as I said first

The 'wrong' and 'not enough' cases validate bug reports.

I don't understand what you mean by this. Bug reports are validated
by the developer reproducing them.
--
Martin Vidner, YaST developer
http://en.opensuse.org/User:Mvidner

Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu
< Previous Next >
References