Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception handling for WPF Application

Tags:

c#

exception

wpf

I have a substanital WPF application set up as follows: Views, ViewModels, Business Objects and Dals, with a SQL Compact DB. Database calls are made via Linq2Sql. Application is single user. (one db per user).

Assuming that an exception occurs within the Dal during an CRUD operation or a user has deleted the database, where should the exception handling take place.

Also if for whatever reason a exception is raised within the View/ViewModel I don't want the system to crash. How should I handle this. Should I just inform the user that an error occurred and recreate the View/ViewModel so that the user can continue. The ViewModels only communicate to other ViewModels via Messenging (e.g. something needs to be refreshed).

like image 279
GoalMaker Avatar asked Dec 10 '25 20:12

GoalMaker


1 Answers

simplest answer would be it really depends what exactly are the requirements of the applications.

Details: First of all you should do exceptional handling where ever there is a chance of an exceptional case. While performing a CRUD operation, while performing something in view model or while even creating views. User definitely won't like the application to crash. So the best thing to do is to handle the exception, customize the error message so that it can make sense to the user and show it to user so that s/he knows an error has been occurred. Also ask user what to do now(it really depends on application requirement again) but for example if databse file has been deleted ask user if he wants to create a new one or things like that

like image 180
Haris Hasan Avatar answered Dec 12 '25 08:12

Haris Hasan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!