Who needs exceptions (was Re: Two languages, too similar, competing in the same space.)

Oleg Broytmann phd at phd.pp.ru
Sat Dec 29 11:56:48 EST 2001


On Sat, Dec 29, 2001 at 03:44:35PM +0000, Gerson Kurz wrote:
> > Ruby has exception handling features, like Java or
> > Python, to make it easy to handle errors. 
> Call me oldfashioned, but I don't like exception handling - I like
> if-then-else and error checking style. Exception handling is cool for
> exceptions - that is: *unlikely* situations -, but it is not cool for
> something as commonplace as open() failing because the file doesn't
> exist.

   Ok, let me call you oldfashioned. Errno chcecking is good in local
context:

   file = open(...)
   if not file: report_error()

But is not so easy to pass errno to upper context. To explain what I mean
I am writing a pice of code using exceptions:

def top():
   try:
      upper()
   except IOError:
      report_error()

def upper():
   data4 = lower()
   process(data4)

def lower():
   file = open(...)
   retunr file.read(4)

Now please rewrite the code without exceptions, using errno checking.

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.




More information about the Python-list mailing list