Hi,
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?
It doesn't, unless you explicitly catch the exception. But if the exception is thrown by your application, isn't there a way to avoid it to happen ? What is the cause of the 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.