Basic: Java return code or throwing exceptions

Sometimes you have this basic question that you  are too shy to ask around because you should know. Reality is that I always have a few of those and eventually you have to look around for what others are doing if you want to get better.

I just completed some code and I was wondering if using the return code for errors was a good idea or if I should have used exceptions everywhere.

After reading a few articles I think that I did the right thing.

One key sentence that I like is: exceptions are for exceptional conditions. So you should see an exception if the failure is not expected and abnormal to the working of your application. A good point.

Others are saying that you should crash loudly. They are saying to use exceptions as much as possible so that it gets your attention and you fix the issue sooner than later.

The argument that return code makes the application more stable seems to be a bit simplistic because you might be hiding issues that will be more difficult to identify later.

There is room for both approach and I think that experience tells you what to do. Always using one or the other does not seem to make sense. Balance.

Return code makes sense right now because this Java code needs to integrate with some Bash code. If the solution was purely Java I think that I would need to change this strategy.

I may start using more checked exceptions since it gives me a better sense of balance and allows to have more information about the failure.

Continuous improvements.

GrepCode

I was searching on how to use some library in my Java code and I came across the GrepCode.com site.

It was great help to find the documentation/code for the library I was using. They only claim to have index for Java, JBoss and Eclipse but the F5 library was there as well.

I installed the Eclipse plugin because that could save some time when searching why I am getting a certain error or why some code is not working as expected.

You find new things every day.

Java 7 Optimization

I have not started to use Java 7 but I have started to read on the differences. This is a great blog post to learn a few new tricks to optimize the JVM:

http://marxsoftware.blogspot.com/2011/10/javaone-2011-definitive-set-of-hotspot.html

It is also funny that the small, almost irrelevant, option is the one that will relieve a serious pain for me:

-XX:+PrintGCDataStamps If this works as I expect we will be able to read GC logs and easily figure out when events have happened

How to be an exceptional programmer

It is funny that sometimes I read an article about a totally different subject but I replace the words and it apply to my aspiration of being a programmer:

How to be an exception photographer

This article highlights the fact that you need to focus on something you like and you are good at. You keep working on it and you become better. This is the way to plan your future compared to trying to being good at everything which will fail you sooner than later.

I have read enough of these articles to know these simple principles. What they also admit in the article is that it is not always easy to find where you are and where you should go. They have a few questions that you should ask yourself and answer honestly to be able to find where you want to go.

They key to success is having a realistic plan and actioning it. Keep working at it. Wishing for results is not enough.