Maybe you cannot classify Exceptions in Fatal/Nonfatal that easily. Forget
about that.
But You will Agree with me that you very rarely want to catch a
StackOverflowException.
An ArgumentException is more common to catch and an IOException belongs to
an absolutely comon thing to catch.
Well, as I said earlier, I can forsee a runtime that provides a more robust
environment for running arbitrary code in sandboxes. In this case when such
an exception occurs I might want to terminate an appdomain, but I would not
want exception to be fatal to the entire app unless that was a policy
decision made by the host.
The Point is to classify Exceptions in expected Exceptions and unexpected
Exceptions and very rare Exceptions that never normally should not occur.
so that you safely can catch an ApplicationException (from my
classification) knowing that you only catch exceptions commonly thrown by
methods.
This way, you have a contract: Methods should never throw Exceptions but
those derived from ApplicationException. If another exception occures
(ArithmeticException, NullReference) or similar, you know something is
wrong.
--
I agree with your intent, but the problem is that the current mechanism
really doesn't support, at least not in a generically useful manner, the
type of categorization you want to do. Given the current architecture and
implementation of exceptions it is most useful when the exception hierarchy
is wide but not very deep. As soon as you try to deepen the hierarchy, which
is what trying to classify exceptions into different categories would do,
you run into all sorts of practical problems that I don't believe can be
overcome. You may come up with perfect categories, but it's only perfect for
your usage.
Even though exception objects are fully object oriented by themselves, and
you can create a complex hierarchy based on them, in practice it does not
appear very useful to create such a hierarchy.
I look at it this way...methods identifies its arguments, both input and
output, and the return value, as types, as specified by the method
signature - this constitutes an API contract. One of the problems with
exceptions is that there is no means of specifying an exception contract -
it is fully untyped, even to the point that there really is no guarantee
that only exceptions that derive from System.Exception will be thrown (code
written in IL can throw integers). This makes it backwardly compatible with
Win32, but it imposes limitations as well. You can constrain the code so
that it only deals with a subset of these, in this case limiting the code to
be CLS-compliant so that it only catches types derived from
System.Exception, but the runtime itself is not so constrained.
The fact that the runtime does not enforce a type system on exceptions, and
because there is no exception contract mechanism that can be enforced by the
runtime, means that the only standards that can be applied are those applied
via coding discipline. One of the truths in computing is that any system
that relies on programmer hygiene is doomed - it must be enforced by a
runtime mechanism for it to succeed.
IMO, a better system would involve high-level abstractions so that exception
contracts, or perhaps more generically, an error contract, could be
specified and to have the CLR participate in this. Perhaps I'm the only one
who sees value in such a system, but in the meantime I'll try to make the
best of what I've got to work with and make do until something better comes
along.