2005年02月21日 星期一 18:37
python-chinese at lists.python.cn,您好! 退订,谢谢,水太大了。 致 礼! liushan_snail liushan_snail at sjtu.edu.cn 2005-02-21
2005年02月21日 星期一 19:58
hw_cg,您好! 谢谢,你这样一说,我清楚了很多。 但是ftplib为什么做了一个all_error,httplib就没有呢? 在 2005-02-21 14:21:00 您写道: >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 致 礼! cry zyqmail at 163.net
2005年02月21日 星期一 22:42
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 µÄÒì³£ÄØ£¿ > > >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
2005年02月22日 星期二 09:19
同理 liushan_snail <liushan_snail at sjtu.edu.cn> wrote:python-chinese at lists.python.cn,您好! 退订,谢谢,水太大了。 致 礼! liushan_snail liushan_snail at sjtu.edu.cn 2005-02-21 _______________________________________________ python-chinese list python-chinese at lists.python.cn http://python.cn/mailman/listinfo/python-chinese --------------------------------- Do You Yahoo!? 注册世界一流品质的雅虎免费电邮 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050222/926053f5/attachment.html
Zeuux © 2025
京ICP备05028076号