网站开发用什么语言最好,电子商务与网站建设论文,代替做网站推广,濮阳住房建设厅网站您可以将finally#xff1a;块与try#xff1a;块一起使用。finally块是放置必须执行的所有代码的位置#xff0c;无论try块是否引发异常。try-finally语句的语法是#xff1a;try:You do your operations here;......................Due to any exception, this may be s…您可以将finally块与try块一起使用。finally块是放置必须执行的所有代码的位置无论try块是否引发异常。try-finally语句的语法是try:You do your operations here;......................Due to any exception, this may be skipped.finally:This would always be executed.......................您不能同时使用else子句和finally子句。示例#!/usr/bin/pythontry:fh open(testfile, w)fh.write(This is my test file for exception handling!!)finally:print Error: can\t find file or read data输出结果如果您无权以写入模式打开文件则将产生以下结果-Error: cant find file or read data相同的例子可以更清晰地写成如下-示例#!/usr/bin/pythontry:fh open(testfile, w)try:fh.write(This is my test file for exception handling!!)finally:print Going to close the filefh.close()except IOError:print Error: can\t find file or read data当try块中引发异常时执行立即转到finally块。执行完finally块中的所有语句后如果在try-except语句的下一个较高层中存在则再次引发异常并在except语句中对其进行处理。