本文介绍了C#中的异常处理:多次尝试/捕获与一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

>解决方案

在我看来,让每个方法只处理一个任务是一个很好的做法。因此,您很少需要在单个方法中拥有多个try / catch块。但是,我没有看到任何问题。



正如Lisa指出的那样,您应该捕获特定的异常,只能捕获方法实际可以处理的异常。


Is it good practice to have more than one try{} catch{} statement per method?

解决方案

In my point of view it is good practice to have each method handle only a single task. As such you'll rarely need to have multiple try/catch blocks within a single method. However, I don't see any problems with it.

As Lisa pointed out you should catch specific exceptions and only catch the exceptions the method can actually handle.

这篇关于C#中的异常处理:多次尝试/捕获与一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 05:37