Search this blog

Tuesday, June 29, 2010

Throw Vs Throw ex

Throw
Throw Ex
try{
        // do some operation that can fail
   }
   catch (Exception ex)
   {
        // do some local cleanup
        throw;
   }
try
   {
        // do some operation that can fail
   }
   catch (Exception ex)
   {
        // do some local cleanup
        throw ex;
   }
It preserve the Stack information with Exception
It Won't Send Stack information with Exception
This is called as "Rethrow"
This is called as "Breaking the Stack"
If want to throw new exception,

throw new ApplicationException("operation failed!");
If want to throw new exception,

throw new ApplicationException("operation failed!",ex);

Finalize Vs Dispose

Finalize
Dispose
Implicit way to destroy the object
Explicit Way to Destroy Object
It Cannot Override
It Can be Override
It freed up the memory used by the object only when scope of the expired
Dispose is forcibly freed up the memory
It is called by GC at runtime
It is called by user
If you call finalize, it will move to finalize queue, GC will finalize the object by freed up the memory
It will directly freed up the memory
It will be handling by GC, no inconsistent error occur
Error will occur, because it is not controlled by GC