Python论坛  - 讨论区

标题:[python-chinese] 我要退定

2005年02月22日 星期二 10:18

Linweixuan linweixuan at gdcattsoft.com
Tue Feb 22 10:18:37 HKT 2005

我也要退定,谢谢!!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050222/a57ce6d3/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年02月22日 星期二 11:14

cry zyqmail at 163.net
Tue Feb 22 11:14:07 HKT 2005

hw_cg,您好!

多谢您!我清楚了很多以前不明白的疑惑。

在 2005-02-22 09:26:00 您写道:
>说的有道理, 在模块级确实是不应该捕获自己不关心且不能处理的异常的. 
>这也是ftplib中的all_error为什么只定义了几种Exception,而不是把所有的异常都包括的原因.
>因为它也是只想处理自己能处理的异常.
>all_error = ( socket.error, IOError, EOFError,  httplib.HTTPException, Exception )
>
>
>但是据我观察, cry兄弟的代码已经是业务级的了,甚至可以说是业务逻辑顶层的代码了,
>如果此处再不捕获所有错误, 将直接抛出去给操作系统,导致程序异常中止.
>
>另外,我的异常捕获中还有一些代码以下列注释代替了 
># do something other 
>这里包括将异常重新抛出的处理方式, 具体怎么处理,就看具体业务的需要了.
>
>
>----- Original Message ----- 
>From: "jian wang" <wangjian5748 at 163.com>
>To: <python-chinese at lists.python.cn>
>Sent: Monday, February 21, 2005 10:42 PM
>Subject: Re: Re: Re: [python-chinese]怎么得到httplib的异常呢?
>
>
>> hw_cg,您好!
>> 
>>   补充一点:千万不要在一个接口中捕捉所有异常,只捕捉此接口(或函数或方法)可以处理的异常,
>> 对不能合理处理的异常,应该抛出,留给调用者处理,否则和业务有关的具体异常就无法正确处理
>> 比如象这样的代码就不好:
>> except Exception, msg:
>>     print msg
>>     # do something other
>> 捕捉了所有异常,记住:本级不能合理处理的异常,抛出给调用者处理
>> 
>> ======= 2005-02-21 14:21:29 您在来信中写道:=======
>> 
>> >cry: 你好!
>> >
>> >借鉴其他语言的异常思想,不是这样写捕获语句的.
>> >你的捕获机制不完善,导致你漏掉了一些异常.
>> >
>> >建议你的异常捕获象下面这样分级捕获, 每个异常捕获语句仅捕获自己感兴趣的异常,
>> >最后使用Exception捕获所有未拦截的异常.
>> >
>> >import httplib
>> >import socket
>> >
>> >try:
>> >    conn = httplib.HTTPConnection("127.0.0.1:8080")
>> >    conn.request("GET", "/")
>> >    response = conn.getresponse()
>> >    result = response.read()
>> >    print result
>> >    conn.close()
>> >
>> >except socket.error, msg:
>> >    print msg
>> >    # do something other
>> >
>> >except httplib.HTTPException,msg:
>> >    print msg
>> >    # do something other
>> >
>> >except Exception, msg:
>> >    print msg
>> >    # do something other
>> >
>> >
>> >
>> >
>> >----- Original Message ----- 
>> >From: "cry" <zyqmail at 163.net>
>> >To: "limodou, python-chinese at lists.python.cn" <limodou at gmail.com,python-chinese at lists.python.cn>
>> >Sent: Monday, February 21, 2005 1:26 PM
>> >Subject: Re: Re: [python-chinese] ???′μ?μ?httplib μ?òì3£??£?
>> >
>> >
>> >limodou,您好!
>> >
>> >直接用except:当然是没有问题,但是我需要错误信息呀,比如:
>> >except error,msg:
>> >
>> >
>> >在 2005-02-21 12:22:00 您写道:
>> >>捕获Exception 不要httplib.HTTPException 试试
>> >>
>> >>
>> >>On Mon, 21 Feb 2005 12:5:36 +0800, cry <zyqmail at 163.net> wrote:
>> >>> python,您好!
>> >>> 
>> >>> 我做了如下的代码:
>> >>> try:
>> >>>         conn = httplib.HTTPConnection("192.168.1.103")
>> >>>         conn.request("GET", "/")
>> >>>         response = conn.getresponse()
>> >>>         result = response.read()
>> >>>         conn.close()
>> >>>  except httplib.HTTPException , msg:
>> >>>         print msg
>> >>> 
>> >>> 运行后:
>> >>> Traceback (most recent call last):
>> >>>   File "", line 3, in ?
>> >>>   File "I:\Python23\lib\httplib.py", line 718, in request
>> >>>     self._send_request(method, url, body, headers)
>> >>>   File "I:\Python23\lib\httplib.py", line 739, in _send_request
>> >>>     self.endheaders()
>> >>>   File "I:\Python23\lib\httplib.py", line 712, in endheaders
>> >>>     self._send_output()
>> >>>   File "I:\Python23\lib\httplib.py", line 597, in _send_output
>> >>>     self.send(msg)
>> >>>   File "I:\Python23\lib\httplib.py", line 564, in send
>> >>>     self.connect()
>> >>>   File "I:\Python23\lib\httplib.py", line 532, in connect
>> >>>     socket.SOCK_STREAM):
>> >>> error: (10060, 'Operation timed out')
>> >>> 
>> >>> 错在那里呢?我怎么能控制httplib的exception呢?
>> >>> 我这样处理ftplib就可以。
>> >>> 
>> >>> 谢谢。
>> >>> 
>> >>>                     致
>> >>> 礼!
>> >>> 
>> >>>             cry
>> >>>             zyqmail at 163.net
>> >>> 
>> >>> _______________________________________________
>> >>> python-chinese list
>> >>> python-chinese at lists.python.cn
>> >>> http://python.cn/mailman/listinfo/python-chinese
>> >>> 
>> >>
>> >>
>> >>-- 
>> >>I like python! 
>> >>My Blog: http://www.donews.net/limodou
>> >>New Maillist: http://groups-beta.google.com/group/python-cn
>> >>_______________________________________________
>> >>python-chinese list
>> >>python-chinese at lists.python.cn
>> >>http://python.cn/mailman/listinfo/python-chinese
>> >
>> >                    致
>> >礼!
>> >
>> >            cry
>> >            zyqmail at 163.net
>> >
>> >
>> >_______________________________________________
>> >python-chinese list
>> >python-chinese at lists.python.cn
>> >http://python.cn/mailman/listinfo/python-chinese_______________________________________________
>> >python-chinese list
>> >python-chinese at lists.python.cn
>> >http://python.cn/mailman/listinfo/python-chinese
>> >
>> 
>> = = = = = = = = = = = = = = = = = = = =
>> 
>> 
>>         致
>> 礼!
>>  
>> 
>>         jian wang
>>         wangjian5748 at 163.com
>>           2005-02-21
>> 
>> 
>
>
>--------------------------------------------------------------------------------
>
>
>> _______________________________________________
>> python-chinese list
>> python-chinese at lists.python.cn
>> http://python.cn/mailman/listinfo/python-chinese
>> _______________________________________________
>python-chinese list
>python-chinese at lists.python.cn
>http://python.cn/mailman/listinfo/python-chinese

                    致
礼!

            cry
            zyqmail at 163.net




[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年02月22日 星期二 12:25

=?GB2312?Q?=CE=CC=8F=AA?= wy1.5 at 163.com
Tue Feb 22 12:25:10 HKT 2005

python-chinese=A3=AC=C4=FA=BA=C3=A3=A1


          =D2=AA=CD=CB=B6=A9=A3=AC=CE=D2=B5=C4=BB=FA=C6=F7=CA=DC=B2=BB=C1=CB=C1=CB
=09

=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=D6=C2
=C0=F1=A3=A1
 =09=09=09=09

=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=CE=CC=8F=AA
=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1wy1.5 at 163.com
=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A1=A12005-02-22





[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号