捕获并赶上(例外五)在C# [英] Catch and Catch(Exception e) in C#

查看:175
本文介绍了捕获并赶上(例外五)在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有是code这三个部分之间没有什么区别,是不是?

I guess there is no difference between these three parts of code, is not it?

   try
    {
       // .............
    }
    catch
    {
        // ............. 
    }

   try
    {
       // .............
    }
    catch(Exception)
    {
       // .............  
    }

try
{
   // .............
}
catch(Exception e)
{
    // ............. 
}

不过我时,应使用第一个和当时几乎精明 - 第二。不过,我想你告诉你的想法。

However I am almost savvy when should be used the first one and when - the second. But I would like you to tell your ideas.

推荐答案

第一个也将赶上抛出的对象是不例外。
这可以从发生不符合CLS code

The first one will also catch thrown objects that aren't exceptions.
(this can happen from non-CLS-compliant code)

第二个将不给一个编译器警告,如果你不实际使用的异常变量。

The second one will not give a compiler warning if you don't actually use the exception variable.

第三个应该只使用,如果你确实需要检查抛出的异常(例如,记录它)。

The third one should be used only if you actually need to inspect the thrown exception (eg, to log it).

这篇关于捕获并赶上(例外五)在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆