Posts Tagged ‘C#’

Visual Studio debugger is too sensitive about exceptions

I was working on XBList the other day when I hit a peculiarity of Visual Studio. I wanted to call a method asynchronously, so I was using BeginInvoke with a callback, as described in this article on MSDN. So I used BeginInvoke to fire off a method, and the method I invoked happened to throw an exception. I didn’t expect this to be a big deal – when the callback was called, I would call EndInvoke which would re-throw the exception and I could deal with it. However, while running in Visual Studio’s debugger, I got a break and an error dialog that claimed I had an unhandled exception. My code never made it to EndInvoke. It said something like “Exception unhandled by user code”.

It turns out that this is just some weirdness in Visual Studio. If you go to the Debug menu, choose “Exceptions…”, and uncheck “User-unhandled” for Common Language Runtime Exceptions, the exception will get properly thrown when EndInvoke is called, and everything’s fine.

exceptions-setting

It’s annoying that I have to give up the relatively useful unhandled-exception trapping that the Visual Studio debugger gives me, but I guess there’s no other way around it.

Posts I haven’t written

I haven’t been updating this blog too much recently. I never meant for this blog to run on a schedule, but I did intend to post more frequently than this. My original idea was that the blog would serve two major purposes. First, it is a place for me to announce new projects or updates to software and websites I’ve already released. It’s done that quite well, though I haven’t had much to announce recently. My job has been taking the majority of my development time, and most of the projects I’ve been working on at home are either private or haven’t been released in the form I’d like to because my employer hasn’t approved them for release yet.

The second major purpose for my blog is as a place for me to record the solution to problems I run across while developing software, so that others won’t have to spend hours Googling or using trial and error to come to the same conclusion. I didn’t intend to rehash things that were easily found or that had already been discussed – only to post when I felt it was something that added value to the internet that hadn’t been there before. So a lot of the blog posts are not really a narrative or running commentary – they’re not meant to be subscribed to, but found individually. It’s for this reason that my most popular posts tend to include the exact text of error messages. This type of post has suffered both because I haven’t been doing as much development, because I can’t discuss a lot of what I’ve learned due to the nature of the projects I’m working on, and because I’ve been learning new stuff (like Ruby on Rails) and haven’t done enough to have solved problems others haven’t already posted solutions for.

The third reason I have this blog is to occasionally talk about my thoughts on different technical topics, from web development to video games. Again, I don’t like to make a post unless I think I’m adding something new, and most of the topics I’ve wanted to talk about have already been covered. I had a lot of draft posts sitting around about web development, web standards, and the evolution of browsers, but then I discovered Alex Russell’s blog and it turns out he’s already said most of what I wanted to say, and better than I could. Other stuff, like my impressions of Windows Vista, critique of stackoverflow.com and suggestions for the Xbox Live Arcade lineup, have been covered to my satisfaction in plenty of places. Maybe some of them will end up posted, but probably not.

Another part of the reason I haven’t posted much is the sheer weight of unfinished posts I have. Right now I have 64 drafts and only 52 real posts! So I’m going to attempt to clear things out by writing a little about what I haven’t posted. A lot of this stuff wasn’t posted because it fell under that third point above, but some of it I was just too lazy to flesh out into real posts. Some of it’s just random stuff. So here’s what’s been happening in the last year:

(more…)

JavaOne 2007

I had the opportunity to go to the JavaOne conference two weeks ago, in San Francisco. It was quite an experience for me as I had never been to a technical conference before, let alone one of that size. I’m not exactly a Java enthusiast, but I am a Java developer. I spend most of my day writing Java code, so going to all the presentations about making better Java code, as well as interacting with Java developers from all over the world, was really educational.

I noticed a few things from the conference that I wanted to write down before I forgot. The first is that even in Java-land, scripting languages are hot. Lots of people were talking about JRuby, Groovy, JavaScript, JavaFX Script, and more. JRuby in particular was getting a lot of excitement from everyone who’s been hearing for the last couple years about how cool Ruby on Rails is. I’ve seen a lot of Rails demonstrations and they’ve failed to impress me but the Ruby language itself is very appealing, especially to someone like myself who mainly scripts in Perl or JavaScript. I’ve definitely been convinced to use Ruby for my next personal web app project, and the combination JRuby’s speed and native access to Java code will make me feel a lot better about it.

There were a lot of talks about static analysis tools, and FindBugs in particular. I’ve been using FindBugs on my Java code (and FxCop for my .NET code) for quite a while, but a few of the presentations gave me a much better idea of how powerful static code analysis can be. One of the best ideas is using special annotations that more clearly document the intended behavior of your code. Not only does this serve as additional documentation, it helps you design your classes better and helps out your code analysis tools. One of the first things I did when I got back was grab the latest FindBugs release and start sprinkling those magic annotations all over my code, and from now on I’ll be writing them in whenever I write new code.

I also got more in-depth exposure to the REST philosophy, which I had heard a lot about but not really thought about too much. I really like the idea, but until the tools get to the point where I can write up some sort of service description and generate client code like I can do with WSDL, I’m going to hang back a bit. Maybe WADL will catch on. I also got a better explanation of OpenID than I had gotten previously, and I’m really impressed. I like that it’s so simple, and that it can still integrate with technologies like CardSpace in a way that adds value to both sides. I searched for an open implementation of an OpenID provider that uses CardSpace, but it doesn’t look like any exist yet.

Another, less explicit theme at the conference was that the Java community has noticed the great design of C# and the .NET framework and are trying to fit some of that back into Java. I’ve always felt that C# was “Java done right”, and the number of JSRs (Java Specification Requests) that I saw for C#/.NET features is a testament to that. JavaSE 5 already added annotations (attributes), generics, foreach, enums, variable length arguments lists, and autoboxing, all features from C# 1.0 or 2.0. The stuff that’s being discussed for JavaSE 7 and beyond includes “superpackages” that look a lot like assemblies, continuations, a “using” statement, generics that don’t use type erasure, indexers, and switching on strings. I think this is great – C# made a lot of great improvements that were no doubt based at least in part on experience with Java, so it’s natural for Java to get back some of that. I didn’t see much talk of any of the C# 3.0 features like LINQ, object and list initializers, extension methods, etc. I did see some talk about incorporating lambda expressions, though, which would be pretty nice.

Despite the fact that the Java language has some catching up to do, one glaring advantage of Java over .NET became apparent to me while I was there. I’m not talking about the platform-independence advantage, though that is certainly there – I don’t think I could imagine building a large, scalable distributed service with Windows machines. No, what I’m talking about is the community. That’s not to put down the large and active .NET community, it’s just that the Java community is huge. And especially through open source, there’s just a lot more going on. I feel like a large part of this is that Sun and other Java leaders have been willing to incorporate the community’s best products into the standard toolset. Products like ant, Eclipse, Spring, JUnit, and even JRuby are accepted tools. Meanwhile on the .NET side, you’re basically taking whatever Microsoft gives you. And while that can usually be good, Microsoft runs the risk of ignoring the direction people are actually heading in.

In the end, I left the conference with much the same opinion of Java that I had in the beginning. Java is a tool, and a good tool, but not a particularly exciting tool. It does have some exciting features (I love JMX), and after my week in the Moscone Center, I feel like I can be more competent at creating Java-based software. Maybe I just haven’t worked on the right Java projects. I hope as my experience with the platform grows, I’ll be able to contribute more, either through this blog or through open-source projects. And who knows, maybe one day I’ll really feel like a Java Guy.