2010年7月20日星期二

System Exception & Application Exception

You can find them in Visual Studio, Debug -> Exceptions...
System.Data.SqlClient.SqlException
System.IO.IOException
System.ArgumentException
System.NullReferenceException
System.OutOfMemoryException
System.OverflowException
System.DivideByZeroExecption
...

Two categories of exceptions exist under the base class Exception:

•The pre-defined common language runtime exception classes derived from SystemException.
•The user-defined application exception classes derived from ApplicationException.

User applications, not the common language runtime, throw custom exceptions derived from the ApplicationException class. The ApplicationException class differentiates between exceptions defined by applications versus exceptions defined by the system.

If you are designing an application that needs to create its own exceptions, you are advised to derive custom exceptions from the Exception class. It was originally thought that custom exceptions should derive from the ApplicationException class; however in practice this has not been found to add significant value. For more information, see Best Practices for Handling Exceptions http://msdn.microsoft.com/en-us/library/seyhszts.aspx.

If the event is truly exceptional and is an error (such as an unexpected end-of-file), using exception handling is better because less code is executed in the normal case. If the event happens routinely, using the programmatic method to check for errors is better. In this case, if an exception occurs, the exception will take longer to handle.

没有评论:

发表评论