Search code examples
javaexceptionidethrow

Is exception handling different in an IDE than it is during runtime as an exe or jar?


I'm working on a physics program and as time goes on I continue to tie up more and more loose ends with exception handling to prevent freezing and locking up. For Now I am getting certain exceptions in my console such as StringFormatException(s), but this error does not freeze the program nor does it affect run-time in any way, it simply shows up in the IDE's terminal (Eclipse IDE, JRE 7). When dealing with errors such as this one, that (seemingly) do not affect run-time, is it still important to handle the exception even if the program works fine? If I were to export the program as a .jar with only these types of errors not handled, would users even notice? Why do some errors cause large problems while others don't?

Side Note: I'm asking this primarily because in the future, when taking on projects much larger than this one I believe there are going to be times when a vast number of spots in my code may exist where exceptions are thrown but not yet handled. On very large projects involving tens of thousands of lines of code do many programmers dismiss these types of errors that do not affect logic or run-time and conclude that to go back and fix all of them would not be necessary or worth the time? Or is it essential to develop a habit of committing possible error throwing situations to memory and staying on top of all possible errors.

Examples of how software with similar errors to this, ones that allow the program to function as if nothing has happened would be greatly appreciated if you have the source code available and have taken note of this sort of thing.


Solution

  • is it still important to handle the exception even if the program works fine?

    Even if it appears to work fine it may not be. If you get into the habit of ignoring Exceptions you can easily ignore an Exception which is causing a problem.

    If I were to export the program as a .jar with only these types of errors not handled, would users even notice?

    It depends if they see the output.

    Why do some errors cause large problems while others don't?

    Some errors are more serious than others. Ideally you only want serious error or none. Errors which are not too serious are more likely to have subtle problems which are harder/less likely to get fixed.

    On very large projects involving tens of thousands of lines of code do many programmers dismiss these types of errors that do not affect logic or run-time and conclude that to go back and fix all of them would not be necessary or worth the time?

    Its best not to handle or catch an exception unless you are going to do something useful with it. Otherwise it is better to re-throw it provided it will always get logged at the very least.

    ones that allow the program to function as if nothing has happened would be greatly appreciated

    FileNotFoundException, EOFException, NumberFormatException are common exceptions which are handled in code (but rarely just ignored) Google for examples.

    Its almost always a bad idea to pretend an exception didn't occur. If you don't care if something worked or not, you usually don't need it in the first place.