Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception Handling in a gui application

I'm a little lost on how to handle unchecked exceptions in my GUI application.

I e.g. have a function that saves a company newly created by the user in a (embedded) database.

The function for saving the newly created company throws 3 Exceptions:

IllegalArgumentException: If the company or a not null field is null (Manually checked and thrown).

EntityExistException: If the company (it's name) already exists. (Also manually checked and thrown).

PersistenceException: If something went wrong when trying to save. (Catched and rethrown).

The function that calls the saveCompany method catches all 3 Exceptions and then logs them and shows a dialog to the user that an error had occurred.

Im now wondering if i need to catch them at all? Or would it be ok to just let them run up to the globalExceptionHandler (where i can also look them)? And im also wondering what my reaction should be?

Should I tell the user that there was an error and let the program run (cause other parts of the program should function properly) or should I tell him and then end the program (cause it's a programmers error that shouldn't be in there)?

like image 811
Biene Maja Avatar asked Jan 16 '23 08:01

Biene Maja


2 Answers

In case of the IllegalArgumentException you should catch the exception and tell the user to correct the data (do not print the stacktrace).

In case of the EntityExistException the user should be informed that the company already exists, and perhaps he or she should consider updating it.

When the user receives the PersistenceException they should be presented with a dialog window with the stacktrace (and perhaps other data relevant for the developer) and informed to submit a bug report.

like image 180
LuGo Avatar answered Jan 24 '23 22:01

LuGo


So the good news is you're asking all the right questions.

Should i tell the user that there was an error and let the program run (cause other parts of the program should function properly) or should i tell him and then end the program (cause it's a programmers error that shouldn't be in there)?

That is a design question you need to think carefully about. If it is a recoverable error and there is nothing the program can do to continue running, then the program should shutdown without the user having the option. If part of the program must die but other parts may go one, the user should be informed. If the user needs to fix some data so the program can run, the user should be informed as such. Etc. Yes, you are asking the right questions though, you just do actually have to think about them and be judicious.

like image 29
djechlin Avatar answered Jan 24 '23 22:01

djechlin