Raise and Handle Exception Demo
2014-01-02 16:07
393 查看
import sys class MyError(Exception): def __init__(self,value): self.value = value def __str__(self): return repr(self.value) try: f = open('new.in') s = f.readline() f.close() i = int(s.strip()) raise MyError(3*3) except IOError as e: print "I/O error({0}):{1}".format(e.errno , e.strerror) except ValueError: print "Could not convert string to int" except MyError as e: print "My errro occurred,value:",e.value except: print "Unexpected error:",sys.exc_info[0] raise参考 : http://docs.python.org/2/tutorial/errors.html
相关文章推荐
- Microsoft][ODBC Microsoft Access 驱动程序] CONSTRAINT 子句语法错误。
- linker command failed with exit code 1 (use -v to see invocation)解决方法
- No identities are available for signing的解决方法
- Error1error LNK1123: failure during conversion to COFF: file invalid or corrupt
- SHUTDOWN: waiting for active calls to complete.
- 在本人的虚拟手术项目中,实现了利用CSplitterWnd对tabView中的任意子view进行窗口切割,效果跟用CSplitterWnd对CMainFrame完全一致。 (注:本人纯粹为了记录技术,
- hdu_1021 fibonacci again (找规律)
- mpiexec_logon01: cannot connect to local mpd (/tmp/mpd2.console_ycai)
- Nexenta *Raidz* Disk replacement via NMV
- opencv之级联分类器训练opencv_traincascade
- 使用Paint事件重画GroupBox来修改边框颜色
- TIME_WAIT
- Container.ItemIndex 获取到行的序号
- 有关foxmail7.1版本导入联系人名单csv的方法
- Invalidate、OnPaint、OnEraseBkgnd函数
- WaitHandle 类 备忘
- 8583报文详细分析 (转载,原创:小马blog.csdn.net/pony_maggie/article/details/6568192)
- Freeradius : 执行 radiusd -X Failed
- poj 1995 Raising Modulo Numbers
- main(int argc, char **argv)参数argc,argv说明和指向指针的指针变量