Popular Posts

There was an error in this gadget

Sep 22, 2011

Exception Description


We can easily handle exception in c#. Here are some name and their description.

Exception :
Plain vanilla exception; a general container for all exceptions.
When you get one of these exceptions, look at the Message
property for the exact details. If you throw this type of
exception, it is important to supply an easy-to-understand
string to the exception constructor.
ArgumentException :
Thrown if you call a method and one of the arguments is not
valid. Typically, in the Message property you can find the
problem with the arguments. If this exception is thrown, it is
because the contents of the argument are wrong.
ArgumentNullException :
Thrown if you call a method where one of the arguments is
a null value. This could be because you are passing the null
value to the method or one of the arguments has a null value.
ArgumentOutOfRangeException :
 Thrown if you call a method where one of the arguments is not
in the expected range. While this exception sounds similar to
ArgumentException, :
  it is more specialized and targets whether
an argument is in an acceptable range. Check the
documentation of the method or the method implementation
on what the acceptable range is. If you throw this exception,
note the valid range in the error message.
ArithmeticException  :
 Thrown if a mathematical error is generated.
DivideByZeroException  :
 Thrown if you attempt to divide by zero.
FormatException  :
 Thrown if the format of the parameter is not correct. For
example, if a method expects a number to be formatted with
a period and you use a comma, an exception is generated.

IndexOutOfRangeException  :
 Thrown if you attempt to reference an index of an array that
would be beyond the limits of the array. This exception is
thrown if you have not allocated an array and then attempt to
reference an element, or if you attempt to reference a negative
index of the array.
InsufficientMemoryException :
  Thrown if not enough memory is available. Although this
exception is not generated often, it can be generated if you
attempt to allocate an array when you specify something along
the lines of 5 trillion elements (due to an improperly assigned
array size variable).
InvalidCastException  :
 Thrown if you attempt to cast one type to another type that is
not supported. This exception is very common when you use
inheritance and attempt a cast.
NotImplementedException :
  Thrown when using methods or properties without an
implementation. Often, you don’t have time to implement all
of the code at once. For those properties or methods that have
not been implemented, don’t leave an empty property or
method implementation. Instead, throw an exception. Then
you will know if you have forgotten to implement something.
NotSupportedException  :
 Thrown when you attempt to use an interface instance and
a method that cannot work. For example, if you open a readwrite
buffer to a read-only CD-ROM, you will get this exception
when writing to the CD-ROM. If you attempt to read from the
interface instance, an exception will not be thrown.
NullReferenceException :
  Thrown when you attempt to call a method or property of
a variable that has not been assigned with a valid type
instance.
OutOfMemoryException : Similar to InsufficientMemoryException.
OverflowException  :
 Thrown when you attempt to perform numeric operations that
are not supported, such as adding 2 billion to 2 billion using
a 32-bit integer.
SystemException Thrown by the operating system. :
 Do not attempt to derive
from this class.

No comments:

Post a Comment