Let's say I read a bunch of numbers from a text file. Each line is initially a string, I need to parse it to an integer. This is where the first exception might happen -
NumberFormatException thrown by the
Integer.ParseInt method. This is a runtime exception - unchecked exception that I don't have to catch or decorate my method with a throws clause.
What should I do if this exception happens, i.e. user has entered something that is not a number in the text file? Currently I'm just throwing a new checked exception (custom one) to indicate an incorrect format of the file.
And there's one more thing - after I've parsed the numbers, I create an object. The constructor of the object (takes two ints) however throws a runtime exception when the first parameter is larger than the second one. Again, should I catch this exception and throw my custom one?