Showing posts with label exception. Show all posts
Showing posts with label exception. Show all posts

Monday, February 8, 2010

Which exceptions are there in .NET?

On the blog of Mikesdotnetting there is a article which summaries some exceptions from the .NET Framework. So these can be used.

Sunday, August 2, 2009

Throw; versus Throw e;

In Coding Standards is the differents between throw and throw e explained.

What is the difference?
The difference is that 'throw;' the original stack trace persists and 'throw ex' truncates the stack trace after the method where the 'throw ex;' is called.

When using 'throw;'?
When in the try{...} a method is called then you must use 'throw;' to take care that you have the original stack trace.


Example:
// Bad!
catch(Exception ex)
{
Log(ex);
throw ex;
}

// Good!
catch(Exception)
{
Log(ex);
throw;
}

Another alternative is to create a new Exception and pass the current exception as inner exception. The stack trace is shown correctly (complete)


Example:
// Bad!
catch(Exception ex)
{
Log(ex);
throw ex;
}

// Good!
catch(Exception)
{
Log(ex);
Throw new NotImplementedException(“some extra information”, ex);
}

See for more information Fabrice's weblog, Signs on the Sand, Joteke's Blog

Tuesday, April 14, 2009

Always comment your code...

I was reading the
book about debugging and there was a very important part about commenting... I have summarized the following points:

Always document:
- your assumptions
- your approach
- the reasons why you have choosen for this approach

For each function or method:
- what does the routine?
- which assumptions have you made?
- what does every in- and output param contains?
- what are all the posssible return values or the routine?
- document every exception which is directly thrown in this routine

Always document bugfixes which you have made during development. (when available write down the bug number or reference where more information can be found about the bug/solution)

Always throw commented code away, because it is not clear what the meaning is of this in five years...

Always improve your code when you think "This is a hack"

Xml Comments
copied from winnershtriangle

exception: The exception tag allows a method's exception handling to be documented. The cref attribute allows the namespace of the exception handler to be included. Example: Throws an exception if the customer is not found.

permission: The permission tag can be used to describe any special permissions a specific object needs. The object to which the permission refers is included as the cref attribute. Example: Class needs to write to the file system, ensure user has appropriate access.

Monday, December 1, 2008

Guidelines for Exception handling

On the blog Marc's Musings I have found some guidelines for Exception Handling. So now when you use a try...catch check this guidelines for correct usage...

See
http://musingmarc.blogspot.com/2005/09/exception-handling-in-net-some-general.html