Try..Catch, Warning Level 4, and Warnings as Errors

Lance worries about people declaring a variable in their catch statement when it is not used in the catch block.
 
There is already a solution to this: compile as warning level 4, and treat warnings as errors. That will pick up this error for you.
 
I would recommend always building at level 4 and treating warnings as errors. This will let you lean on the compiler to help you create clean code.
 
In addition beware the other two evils of exception handling: using throw ex; instead of throw; which means the call stack will now be from this throw point, not the point the exception was raised, and swallowing exceptions (in other words catching something you do not know how to resolve). Always prefer fail-fast to catching an exception. You want to know about your errors, not hide them. Only software that needs to remain up in the presence of errors should have a swallowing exception block and even then you need to at least log that the exception happened and understand the exception guarantees enough to be sure of how to proceed.
 
 
 
 
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

10 Responses to Try..Catch, Warning Level 4, and Warnings as Errors

  1. Unknown says:

    wow gold wow gold eve isk wow power leveling wow power leveling wow power leveling wow power leveling warhammer gold warhammer power leveling bestchina traveland ugg bootsor ghd straighteners

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s