Archive for the ‘Programming’ Category

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…)

Eclipse NoClassDefFoundError near installFont on startup

At work and at home I use Eclipse as my IDE of choice for Java development, along with Eclipse-in-disguise Aptana for web development. I’ve never had a problem with Eclipse on Windows or on my Mac, but on my Linux machine (and many of my co-workers’ machines) Eclipse tends to crash rather violently. I suspect that it isn’t Eclipse at all, but the primitive P4WSAD Perforce plugin. I don’t use Perforce at home, so that might be the difference. Anyway, what happens is that in the middle of doing something Eclipse will run out of PermGen memory, throw up some errors, and die in the least pleasant way possible. When you try to start it back up, you get something like this:

 !SUBENTRY 1 org.eclipse.team.core 4 0 2007-08-20 16:58:25.979
 !MESSAGE Could not instantiate provider com.perforce.team.core.PerforceTeamProvider for project SampleProject.
 Exception in thread "Thread-1" java.lang.NoClassDefFoundError
         at org.eclipse.ui.internal.themes.ThemeElementHelper.installFont(ThemeElementHelper.java:101)
         at org.eclipse.ui.internal.themes.ThemeElementHelper.populateRegistry(ThemeElementHelper.java:57)
         at org.eclipse.ui.internal.Workbench$28.runWithException(Workbench.java:1426)
         at org.eclipse.ui.internal.StartupThreading$StartupRunnable.run(StartupThreading.java:31)
         at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
         at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:123)
         at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3296)
         at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2974)
         at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2309)
         at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
         at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
         at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
         at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
         at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
         at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
         at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:153)
         at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
         at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
         at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
         at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:504)
         at org.eclipse.equinox.launcher.Main.basicRun(Main.java:443)
         at org.eclipse.equinox.launcher.Main.run(Main.java:1169)

Further digging reveals that the culprit is definitely the Perforce plugin. To fix it, you need to go to where Eclipse is installed, and move the plugins/com.perforce.* files away. Then start Eclipse, which will start but complain about the missing plugin. Then shut down Eclipse, move the plugins back, and start up again. You’ll need to reconfigure any Perforce windows you had open, but at least Eclipse will start.

This seems to be caused by Eclipse crashing after running out of PermGen memory. To prevent future crashes, edit eclipse.ini in your Eclipse install directory. It should look something like this:

-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
-vmargs
-Xms40m
-Xmx512m
 -XX:MaxPermSize=256m
-Dosgi.bundlefile.limit=100

The -XX:MaxPermSize is especially important for preventing Eclipse crashes. The other option, --launcher.XXMaxPermSize only works in Windows.

WebLinkLabel Windows Forms Control

While I was updating my PopupNotify control today, I realized that I had created another useful little control for XBList that I hadn’t released, the WebLinkLabel Control. This simple control wraps the standard LinkLabel control to make it easier to embed multiple hyperlinks in a label, each of which will load up a URL in the user’s default browser when clicked. It’s not the most complex thing in the world, but it has proven useful for inserting help links into XBList’s error dialogs, so I suspect it might be of some utility to others. Using it is about as simple as using a standard Label. Just drag the WebLinkLabel onto your form, customize it however you like, then assign a specially-formatted string to the Text property. You use “url” tags to specify where you want links, like this: “Hello, this is text <url=http://brh.numbera.com>with a link in it</url>.” You can of course have as many links, pointing to as many different URLs, as you would like. If you want to get that formatted string back out, use the LinkText property, or if you want to get a flattened view out (“Hello, this is text with a link in it.”), use the Text property.

This code is licensed under the LGPL, like the other XBList bits I’ve released. As usual, I would appreciate it if whoever uses this code would email me to let me know how they’re using it, just for my own amusement. You can download the control right here.

New Version of the PopupNotify Windows Forms Control

A couple years back I posted the source of XBList‘s tray notification control on my site as the PopupNotify control. I licensed it under the LGPL so people could use it for their own applications. While I requested that whoever used it should let me know, I’ve never received any email about it until this week, when somebody wrote to tell me that they had been using it but it didn’t work on Vista, and they wanted some help getting it to work. Despite the fact that I would rather they had told me about this beforehand, I’ve taken this as an opportunity to update the component. I just pulled out the current version of the control that I’m using for XBList, which has a much prettier Vista-style look, less P/Invoke calls, and other .NET 2.0 improvements. I’ve left the 1.1 version of the control around for anyone who wants to use it but hasn’t updated to .NET 2.0 yet.

The new, Vista-style popup

Hopefully this component will continue to be useful to other developers, and they’ll let me know if they’re using it in their projects, since it’s just so much more fun to release stuff for free when you get to see it in action.