Académique Documents
Professionnel Documents
Culture Documents
Bugs: These are, simply put, errors on the part of the programmer. For
example, assume you are programming with unmanaged C++. If you fail
to delete dynamically allocated memory, you have a bug.
User errors: Unlike bugs, user errors are typically caused by the
individual running your application, rather than by those who created it.
For example, an end user who enters a malformed string into a text box
could very well generate an error if you fail to handle this faulty input in
your code base.
Exceptions: Exceptions are typically regarded as runtime anomalies that
are difficult, if not impossible, to account for while programming your
application. Possible exceptions include attempting to connect to a
database that no longer exists, opening a corrupted file. In each of these
cases, the programmer (and end user) has little control over these
“exceptional” circumstances.
Exception Classes
System.SystemException:-
This class is for exceptions that are usually thrown by the .NET
runtime or that are considered to be of a generic nature and
might be thrown by almost any application.
Ex- ArgumentException, StackOverFlowException.
System.ApplicationException:-
This class is important, because it is the intended base for any
class of exception defined by third parties.
If you define any exceptions covering error conditions unique
to you application. You should derive these directly from
System.ApplicationException
Catching Exceptions
Catch Blocks encapsulate the code that deals with the various
error conditions that your code might have encountered by
working through any of the code in the accompanying try
block.
try
{
//code for normal execution
}
catch
{
//error handling
}
finally
{
//cleanup
}
Processing Multiple Exceptions
}
catch (Exception e2)
{
throw new CarIsDeadException(e.Message, e2);
}
}
Nested try Blocks
try
{
//point A
try{ //point B }
catch{ //point c}
finally{//clean up}
//point D
}
catch{//error handling}
finally{//clean up}
If an exception is thrown inside the outer try block
but outside the inner try block(points A and D), the
situation is either the exception is caught by the outer
catch block and the outer finally block is executed.
If the excecution is thrown in the inner try block(point