Friday, May 29, 2009

Java: Try...Catch...Finally Flow

Note to self:
JAVA WILL ALWAYS EXECUTE THE FINALLY BLOCK*.

Hence, this code will work:

public static void main(String[] args)
throws Throwable {
try {
if (true) throw new RuntimeException("WOWZA!");
} catch (Exception e) {
throw e;
} finally {
System.out.println("REACHED!");
}
}

Yes, Java's output stream will read "REACHED," followed by the exception trace.

Even this code will work, and the finally block will be reached:

public String getString() {
try {
if (true) throw new RuntimeException("NOOOOOOOOOOO!");
return "STRING";
} catch (Exception e) {
return null;
} finally {
System.out.println("REACHED!");
}
}

Hope this helps someone out there.

* The only time Java will not execute a finally block is when it can't: eg when the JVM is shut down or the current thread is killed outright.

Labels:

Saturday, May 9, 2009

Ubuntu: Record Your Desktop

For the longest time, I had been having problems using recordMyDesktop, which is actually a really nice desktop recording utility for Linux: Ubuntu in particular. The gtk-recordMyDesktop package provides a really nice front-end for the internals of the screen recorder.

Now, I've had far too many problems to list when using recordMyDesktop, so many, in-fact, that it basically made it impossible for me to do any real recordings. On Ubuntu 8.04 Hardy Heron (my first Ubuntu distro), recordMyDesktop was sketchy at best, and would basically fail all of the time. I could record reliably for about 10 seconds about 50% of the time, without audio. Luckily, it seems pretty reliable on my new Ubuntu 9.04 Jaunty 64bit distribution.

I recently bought a Plantronics USB headset by which to do my screencasts, and that has given me no end of troubles, until now. When I'd record my desktop in the past, the audio would be horrible, all jumbled and super fast: compacted into the first few seconds of the recording. Then I realized how stupid of a mistake I overlooked. I needed to set the kHz to the right setting. By default, recordMyDesktop uses 22100 Hz, which gave me horrible results. 44100 Hz gave me crappy audio too, but only after I punched in '48000' Hz did I get awesome audio.

This mistake of mine was especially hilarious because I used to do audio recording, production, and mastering all of the time using my Windows XP machine and Cakewalk's Sonar 6. To this day, I still use Sonar from time to time, as it's basically the best DAW available anywhere. (My main computer is kind of screwed up right now, but that's another story.)

Basically, the point is this: if you're recording from an audio source and getting jumbled, crazy-sounding audio, try different Hz/kHz settings and different bit-rates. This should go without saying, but hey, we all make mistakes sometime.

Labels: , , ,

Ubuntu 64: Running Flex Builder

I can't claim any credit on this one, but I got Flex Builder working on my new Jaunty distribution! I initially thought I should get myself a 64bit version of Eclipse and try to install Flex Builder over it, but that didn't work.

Evidently, the solution is to get a 32bit JRE and get that running, then to modify Eclipse's startup files to point to the 32bit JRE. Everything works great! I was basically able to copy and paste my old Ganymede from a 32bit OS to a 64bit one, with only a few modifications. Pretty dang cool. Anyway, here's where the credit is due: http://rachaelandtom.info/content/running-32bit-eclipse-64bit-linux

As far as running a 32bit Flash Debug player, I haven't given that the time to work on getting that to work. I'm for the moment satisfied to just have Flash Player work regardless. The 64bit standard player is working great for me, I haven't had too many problems with it. Here's hoping that I won't have to get a 32bit Firefox to run the Flash 10 Debug Player :)

Labels: , , , ,