Now This Is Some Exceptional Code

I have been re-writing large chunks of Vrui recently, primarily to support a new Vulkan-based HMD graphics driver that will warp and distortion-correct rendered application image frames to an HMD operating in “direct mode,” i.e., without being managed by the window manager. Yes, I know I’m several years late to that particular party. 🙂

While I was doing that, which involved staring at a lot of old code for extended periods, I also cleaned up some things that had been bugging me for a long time. Specifically, error handling. I like descriptive error messages, because I find they make it easier to pin-point problems encountered by users of my software who are not themselves programmers, like, say, people who install an AR Sandbox at their location. I like it when an error message tells me what went wrong, and where it went wrong. Something like “I’m currently in method Z of class Y in namespace X, and I can’t open requested file A because of operating system error B.” In other words, I want error messages tagged with a location like “X::Y::Z,” and with parameters like a file name or OS error code. I also want to use exceptions, obviously. Unfortunately, C++’s standard exception classes don’t have methods to create exception objects with parameters, so, a very long time ago, I decided to roll my own.

Continue reading