首页 > 编程语言 > 详细

[Python]How to handle the exception in Python?

时间:2014-09-19 15:44:15      阅读:353      评论:0      收藏:0      [点我收藏+]

This post demonstrates how to use try clause to handle the exceptions

def test_exception(case=None):
	print case
	try:
		if case is None:
			raise ValueError("there is no value")
		elif case == 1:
			raise ImportError("can not import the module")
		else:
			raise MyException("this is the special error")
	except MyException as e:
		print e
		print "this is my exception"	
	except ValueError as e:
		print e
		print "this is value error"	
	except Exception as e:
		print "this is exception "

class MyException(Exception):
	pass

if __name__ == "__main__":
	#test_exception()
	test_exception(1)

 

[Python]How to handle the exception in Python?

原文:http://blog.csdn.net/wonderfan/article/details/39397357

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!