Exceptions in C# provide a structured, uniform, and type-safe way of
handling both system level and
application-level error conditions. [Note: The exception mechanism is C# is
quite similar to that of C++,
with a few important differences:
? In C#, all exceptions must be represented by an instance of a class type
derived from
System.Exception. In C++, any value of any type can be used to represent an
exception.
? In C#, a finally block (§15.10) can be used to write termination code
that executes in both normal
execution and exceptional conditions. C++ has no equivalent construct.
? In C#, system-level exceptions such as overflow, divide-by-zero, and null
dereferences have well
defined exception classes and are on a par with application-level error
conditions.
end note]
handling both system level and
application-level error conditions. [Note: The exception mechanism is C# is
quite similar to that of C++,
with a few important differences:
? In C#, all exceptions must be represented by an instance of a class type
derived from
System.Exception. In C++, any value of any type can be used to represent an
exception.
? In C#, a finally block (§15.10) can be used to write termination code
that executes in both normal
execution and exceptional conditions. C++ has no equivalent construct.
? In C#, system-level exceptions such as overflow, divide-by-zero, and null
dereferences have well
defined exception classes and are on a par with application-level error
conditions.
end note]
本文介绍了C#中的异常处理机制,对比了C#与C++的异常处理方式,并详细阐述了C#中所有异常必须是System.Exception类派生类的实例这一特性。此外,文章还提到了C#特有的finally块,它可以确保无论是在正常执行还是异常情况下都能执行终止代码。
283

被折叠的 条评论
为什么被折叠?



