This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am working on Exception related problem occuring in application. The application java program listens on a port waiting for third party XML message. After receiving the message, program checks for "<" tag and then performs necessary transformation. Program is using String.indexOf() method to do this.If third party does not send message containging "<" then ArrayIndexOutofBoundsException is thrown and thread is killed.
My question is how does program recovers from Runtime Exception?
A RuntimeException indicates something bad with your programming logic/code. This type of exception can be completely avoided by fixing the code/changing the code logic.
In your particular case, String.indexOf() method returns index of "<" in your message or -1 when it does not find it. I believe you are trying to access the array with this index returned. All you need to do is before accessing the array check that the index value returned is >= 0.