English 中文(简体)
特殊渔获量
原标题:Exception catching
  • 时间:2010-08-24 10:36:39
  •  标签:
  • c#
  • exception

不同之处

 try
 {
     ... 
 }
 catch (NHibernate.ADOException exception)
 {}

以及

try
{
    ... 
}
catch (exception ex)
{}
最佳回答

在渔获区,你具体说明了你希望捕获的例外情况。 因此,

try {}
catch(Exception e){}

它将涵盖由例外类别产生的所有例外(所有例外)。 如果有:

try{}
catch (NHibernate.ADOException exception){}

它将只捕获来自或来自《发展权利宣言》的例外情况。 因此,如果你收到“阿古特约”,就会像没有尝试/捕获物一样通过。

问题回答

我假定你指的是你。

catch (Exception ex) {}

和第二版。

然后,区别是,第一种例外情况只能排出一个特定的例外情况,即<代码>NHibernate。 ADOException,而第二种办法则将进入可能被推翻的所有例外的捕获区。

第二种做法通常不正确,因为你要求处理各种可能错误。 然而,从最外面的角度来看,它对于任何通过的例外来说都是一个整体。

强烈建议使用捕获量{例外},因为这实际上掩盖了ug。 在每个可能出现例外的地方,必须只达到预期的例外类型,即使需要写更多的编码线。 当出现意外例外时,方案必须坠毁,这是固定ug的唯一办法。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签