Is it possible to continue a Java program after if it catches and deals with an exception? For example, say I am processing 1000 records from a file, one at a time. If the 6th record causes a Java Exception, I want to be able to skip it and continue processing the remaining 994 records. Is this possible with Java Exception handling? If so, how? Thanks, Irshad [ April 06, 2004: Message edited by: irshad ahmed ]
Irshad- I'm glad you're trying to learn more about Java and how it can help you to deal with problems (and I think you're on the right track with Exception Handling). But please don't post the same thread in multiple forums. It's very confusing and wastes peoples time when they answer a question thats already been answered elsewhere. I'll leave this thread open to continue the discussion. Thanks.
From here, you can report to the user these records were bad, you can use an alternate approach to try to process them, log that they didn't get processed, etc, etc...basically, take whatever action you want to take in response to a bad record. You could write a handleBadRecord(Record r) method that you call from the catch block that does whatever you want. Another common tactic is to create your own exception, and if badRecords.size()>0 once you're done processing, throw that exception with the list of the bad ones to the caller and let them decide what to do. sev [ April 11, 2004: Message edited by: sever oon ]
I would suggest couple of things. First see if you really expect a java exception or a boolean condition. If you can avoid java exception I would suggest doing that because using try/catch in a loop is very inefficient. Second I agree with the previous post about creating your own exception and adding information into that exception within the loop. At the end you want to throw your own exception.