Java: Catching all Exceptions

So here’s the thing. I’m not REALLY a Java guy. Yes I did, however, write most of the starting code for WooMinecraft, but that was more of a test on getting into Java itself, not really to write the plugin.

My day job is as a WordPress developer over at WebDevStudios. So I’m really limited on the time I get to spend with Java, which makes it more of a hobby and a side project. This is evident if you look at the commit logs for WooMinecraft.

However, this weekend I’ve started work on a sort of “remote white-list management” for Minecraft. To get you up to speed, Minecraft, while being a game, is still pretty in-depth if you play modded Minecraft like Feed the Beast or Tekkit, or other packs. Anyhow, I’m not going to try to explain it completely, but basically for me, Minecraft is a Java playground.

So What’s the Problem?

Earlier today I was writing some java code based on a StackOverflow question, which basically was “How do I do an HTTP Request in Java”, simple right? Well in WordPress we have something nifty called wp_remote_get() or _post() respectively.

Pretty simple in WordPress, we don’t have to deal with input streams, connection parameters ( unless we want to ). Granted, I should note that wp_remote_get is a wrapper for a few things, but still, it makes it super simple…

How Java Differs

Well, if it’s not obvious, Java is NOT WordPress. But aside from that, the code I found on StackOverflow today was well, still quite simple:

However, in the interest of ‘handle all the things’ I figured, I could do it BETTER!!! Remember, I’m still a java noob, so better isn’t always better. Mainly I thought it best to catch ALL exceptions, so I made this: