- Exception represents a single piece of information.
- Exceptions are (or should be) by definition rare occurrence in application lifetime so boxing, unboxing and copying are not an issue I think.
- Exceptions almost always go out of scope from where they were created, so there is a risk of having reference to exception stored somewhere making it good candidate for promotion to next GC generation, while structs are easier to cleanup.
- Immutable Struct is thread safe.
You never want Exception to be null (even compiler or CLR forces this, try doing whats below):
throw null;
then, you'll get:
NullReferenceException
异常为什么是类,有何特定原因吗?
catch
工作方式是基本的(即,你从最具体到最一般派生的异常中catch
以处理特定情况)。 - Matthew Watson