可以在可能报错的位置添加
try
{
// try to do something that may cause a exception
}
catch(OneException oe)
{
// catch the exception
// solve it or throw
}
catch(AnotherException ae)
{
// catch another exception
// solve it or throw
}
catch
{
// catch all other exceptions
// solve it or throw
}
final
{
// whether a exception occured or not
// this block will be executed
}
结构,来捕获异常,并针对异常做出相应的判断和处理;
程序报错说明程序中存在问题\异常,绝对不能放任不管。而强行捕获所有异常并不作处理,也不继续抛出,更是不可取的方法。
参考资料:https://msdn.microsoft.com/zh-cn/library/0yd65esw.aspx
另多说一句,msdn.com是C#/VB程序员的最好的老师