如果使用这种格式:
finally中的exceptions将不能被正确处理。
finally中将处理try中出错后的一些事情(如sql出错后,关闭数据库连接),而catch中将处理try和finally中的异常
- try {
- code that might throw exceptions
- } catch (Exception e) {
- show error dialog
- } finally {
- code that might throw exceptions
- }
如果使用另一种格式:
- try {
- try {
- code that might throw exceptions
- } finally {
- code that might throw exceptions
- }
- } catch (Exception e) {
- show error dialog
- }