I lost a bit how to handle thrown exceptions in my graphics application.
I, for example. have a function that saves the company created by the user in a (built-in) database.
The save function of a newly created company throws 3 Exceptions:
IllegalArgumentException : If the company or non-empty field is NULL (manually checked and selected).
EntityExistException : If the company (this name) already exists. (Also checked manually and throws).
PersistenceException : If something went wrong when trying to save. (Hooked and abandoned).
The function that calls the saveCompany method catches all 3 Exceptions, and then writes them to the log and shows the user a message that an error has occurred.
Now I wonder if they need to be caught at all? Or would it be ok to just let them run to globalExceptionHandler (where can I also see them)? And they are also interested in what should be my reaction?
Do I have to tell the user that an error has occurred and let the program start (because other parts of the program must function properly), or should I tell him and then end the program (cause a programmer error that should not be there)?
source share