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

Gerson Kurz gerson.kurz at t-online.de
Sat Dec 29 11:16:03 EST 2001


On Sat, 29 Dec 2001 19:56:48 +0300, Oleg Broytmann <phd at phd.pp.ru>
wrote:
>   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.

def top():
    if not upper():
        return report_error("upper failed()")

def upper():
    data = lower()
    if data:
        process(data)
        return 1

def lower():
    file = open(...)
    if file:
        return file.read()
    report_error("lower failed()")

So ? After all, C doesn't need it, and I think few C programmers would
call this feature the "most missing", or? 

========= WAS CANCELLED BY =======:
Path: news.sol.net!spool1-milwwi.newsops.execpc.com!newsfeeds.sol.net!news-out.visi.com!hermes.visi.com!out.nntp.be!propagator-SanJose!in.nntp.be!news-in-sanjose!news-xfer.nuri.net!feeder.kornet.net!news1.kornet.net!ua4canc3ll3r
From: gerson.kurz at t-online.de (Gerson Kurz)
Newsgroups: comp.lang.python
Subject: cmsg cancel <3c2deb81.11823921 at news.t-online.de>
Control: cancel <3c2deb81.11823921 at news.t-online.de>
Date: Mon, 31 Dec 2001 04:35:16 GMT
Organization: A poorly-installed InterNetNews site
Lines: 2
Message-ID: <cancel.3c2deb81.11823921 at news.t-online.de>
NNTP-Posting-Host: 211.57.49.2
X-Trace: news2.kornet.net 1009774671 27193 211.57.49.2 (31 Dec 2001 04:57:51 GMT)
X-Complaints-To: usenet at news2.kornet.net
NNTP-Posting-Date: Mon, 31 Dec 2001 04:57:51 +0000 (UTC)
X-No-Archive: yes
X-Unac4ncel: yes
X-Commentary: I love NewsAgent 1.10 and the Sandblaster Cancel Engine Build 74 (19 March 1999)

This message was cancelled from within Mozilla.



More information about the Python-list mailing list