# Monday, January 26, 2009

If you’ve been writing .NET applications for a while, you’re likely aware that you’re not supposed to just throw Exception. Instead, if you’re dealing with a null argument, you should be throwing an ArgumentNullException instead. FxCop warns against cases like this.

My problem isn’t knowing to not throw Exception. My problem is finding the appropriate exception to throw.

Just about every time I need to throw an exception in code, I type something like throw new… then wait for intellisense, and then inevitably try to type something like *Exception. Which fails of course. Then I do a google search for common exception types and will come across a post like Brad Abram’s Common Exception Types. Which is somewhat useful, except that his list only contains Exception names including Exceptions like the InvalidProgramException, which has a description of “the exception that is thrown when a program contains invalid MSIL.” Most likely not what I need :-) Jeff Atwood has an older post about a console application he wrote to write out Exception types from assemblies, but once again, it doesn’t provide the description I needed to help make my decision, too.

So, I decided to solve this problem myself.

I liked Jeff’s approach because it was lightweight and could be piped to programs like findstr so that I could look for certain types of exceptions. I essentially wanted what he had, but I wanted summary information as well. I ended up solving the problem with PowerShell. First, check out the output:

[3] » Get-Exception Null | Format-List

Name    : System.ArgumentNullException
Summary : The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method that does not
          accept it as a valid argument.

Name    : System.NullReferenceException
Summary : The exception that is thrown when there is an attempt to dereference a null object reference.

Name    : System.Management.Automation.PSArgumentNullException
Summary : No summary found.

Name    : System.Data.NoNullAllowedException
Summary : No summary found.

Name    : System.Data.SqlTypes.SqlNullValueException
Summary : No summary found.

As you can see, my script is called Get-Exception and it can handle searches. The results can be passed to the various formatting cmdlets like Format-List. You can also pipe the results to Select-String for further searching if you wish or just pipe it to a Where statement.

The script itself is fairly simple. The pulling of exception types is based entirely off of the following statement:

$exceptions = [System.AppDomain]::CurrentDomain.GetAssemblies() | foreach {   
    $_.GetTypes() | where { $_.FullName -match "System$filter.*Exception$" }  
}

To pull the summary documentation, I’m using the returned type’s Assembly.Location property and checking for an XML file with the same name at the same location. This usually equates to an XML file in C:\windows\microsoft.net\framework\v2.0.50727. Then I use an XPath expression against it.

I’ve posted the script out on the PowerShell Code Repository at http://poshcode.org/827 if you’re interested in downloading it and trying it out. There are a lot of other great scripts there as well.

posted on Monday, January 26, 2009 7:47:21 AM (Central Standard Time, UTC-06:00)  #    Comments [3]
# Monday, January 12, 2009

Tonight, the FSDNUG group participated in their first launch event ever – for SQL Server 2008! Woo!

The gist of it was that 4 of us took about 15 to 20 minutes to talk about different portions of SQL Server. It turned out to be more intro than deep dives, but I think the group got more out of the presentation this way.

My portion of the presentation was on SQL CLR.

I think my talk went alright, but my demo definitely didn’t work. I blamed the Windows 7 beta but it probably had more to do with my lack of knowledge. *shrug* If you’re interested in trying the example out for yourself, Bashar Kokash has a good post on it. The example worked fine on my machine without any problems the first time, but during the talk, the Visual Studio deployment apparently didn’t work. Oh well.

The other code examples that I had all are linked off of the MSDN overview of SQL CLR link from above, so knock yourself out. Keith Elder’s post on creating custom SQL CLR user-defined types is also a good start.

The final two links I used were this one from SQL Skills and this one… that provided most of my information :-) Thanks Google!

I enjoyed the chance to present again! If you have any feedback, feel free to let me know.

posted on Monday, January 12, 2009 10:09:06 PM (Central Standard Time, UTC-06:00)  #    Comments [0]
# Thursday, January 01, 2009

So, a year ago to the day, I posted my review of 2007 with a look towards 2008. To continue that age old tradition, I will now review 2008.

Learning

I started off the month by stating that I wanted to learn some new languages, primarily Python and Ruby. I’m sad to say that I haven’t made it past the 5th python challenge yet. I pretty much got distracted, which is a lame excuse. On the other hand, instead of learning languages, I’ve learned a ton about editing in VIM and even a little about Emacs (though I have to use viper or vimpulse to be at all productive in Emacs). I’m even using ViEmu in Visual Studio. The Vim key-bindings have become muscle memory now and I consider that a positive thing. I’m still going to try to learn other languages this year, but I’m going to need a project to work on before I can become proficient.

FSDNUG

This year, a very exciting thing for me was the formation of FSDNUG. Michael Paladino pretty much did all of the work, but he lets me call myself a co-leader. Raymond Lewallen opened up the FSDNUG meetings by speaking about Behavior Driven Development. I didn’t really grok BDD at that point, but I’m learning. I most definitely prefer the context/specification style of naming specs over traditional TDD test names.

Conferences

I was fortunate enough to attend both Tech Ed and DevLink this year. I even told people at DevLink that I’d be attending CodeMash, but I sadly won’t be able to make it after all. I have no doubts that it will be an amazing conference, though, and wish I could be there.

Presentations

I presented on PowerShell three times in 2008. Once to FSDNUG, once to MNUG and then once to Harding University CS students. My presentations pretty much took up all of September. It was a great experience and I’m looking forward to speaking to the Shreveport .NET User Group in March!

Posts

My post on “real world debugging witn WinDbg” post was featured on the Tech Ed bloggers site, which led to me being selected as a “featured Tech Ed blogger” for a day. I was also excited to have my PowerShell thumbnail script mentioned on the PowerScripting Podcast.

In closing…

All in all, a really great year. I noted in 2007, that it had been the year of the most growth for me as a developer. That was true… at least until 2008. My opinion right now is that there is no such thing as a good developer, only a better developer. This saying comes from a discussion I had with a coworker a few months back where we came to the conclusion that there isn’t such a thing as a good design or architecture, only a better design or architecture – all because we’ll inevitably have learned a better way to do things in the future.

I hope everyone has a great 2009!

posted on Thursday, January 01, 2009 2:13:41 PM (Central Standard Time, UTC-06:00)  #    Comments [1]