I am giving a presentation titled "Exception Management Strategies" at Luzerne County Community College for the .NET User Group's monthly meeting.  If you haven't done so yet, please register and I'll see you there.


 
Categories: .NET | C# | Community | Software Development | VB.NET

November 26, 2007
@ 07:00 PM

I’m often asked to assist with some basic exception handling strategies for code. Below are a few exception handling pointers and hopefully expand on them in later posts.

· After identifying suspect code, determine if it will benefit from exception handling, the tester-doer pattern or the try.parse pattern. There are some times you won’t want to use a try/catch, (e.g. check to see if a connection is closed first before closing it rather than wrapping the close call in a try catch).

· Where possible, catch specific exceptions, not just System.Exception. (i.e. If you know the exception to be caught will be a SqlException, catch that)

· Don’t use return error/success codes and rely on other developers (or yourself) to use or check the value of return codes. More often than not, return values/codes from a function are just wasted.

· Exceptions aren’t always errors. Exceptions can represent errors but they can represent anything that isn’t ordinarily going to happen during the execution of your code, and that isn't always an error.  

· Use the finally block. You’ll be able to save half the coding and coding around other code you’d normally need to do without it. If you don’t use a finally block, not only will you have to check for specific states of variables yourself to cleanup code when an exception has occurred, but you will have to check these flags/variables again when things run smooth.  Finally trims code and makes things smoother.

· Make sure the state of the application hasn’t changed after the exception. There is one of two states that you want to leave an application method after an exception, 1) the state the app was in before the method call or 2) as if the method had never run before.  Either way, if an exception occurs, you have some work to do to make sure the app state is solid.

· Users should never have to see or deal with an exception that has been bubbled all the way up the stack. Not only does break the state rule but the user has just lost confidence in this application.   The only worse thing you can do to the user now is to have the app hang all day.

· Log all exceptions. By logging all exceptions, you can generate information, metrics and reports about the internal state of the program to perform diagnostics and create a better quality version next release.


 
Categories: .NET | C# | Software Development | VB.NET

October 29, 2007
@ 10:58 AM

Multitargeting is targeting specific versions of the .NET Framework, in the Visual Studio 2008 Betas and later you can target the 2.0, 3.0 and 3.5 frameworks for development. 

So, why multitarget?  You may have to support existing code bases that were previously written using Visual Studio 2005 targeting the .NET 2.0 Framework with AJAX 1.0 and want to upgrade just your Visual Studio IDE to take advantage of new feature sets.  Or, you may have directives from management, company or client policy to keep creating on the 2.0 codebase until further notice.   Whatever the reason, you can target the version that’s right for your project.

How to target different framework versions: 

You can select the framework version you want when you start a new project or website.  The project type doesn't matter, multitargeting is available for Winforms, ASP.NET or any type of project template you decide to use.


Once you've started your project, if version requirements change at any time, you can adjust easily.  You can target different versions by visiting the project properties dialog box and selecting the Build tab (left side).   The versions available to target will display on the right (circled below).




And that's all there is, it's easy to try out different .NET framework versions or switch versions using Visual Studio 2008.

 
Categories: .NET | ASP.NET | C# | VB.NET | Visual Studio

October 24, 2007
@ 02:46 PM
Download the VB9 Beta language specs here.  And the C# version is here.  There's some new great features listed in the VB9 specs, I'm looking forward to digging into query expressions, generic type inference and partial methods (all described in the VB doc).


 
Categories: .NET | VB.NET | C#