1

I am developing a new desktop application from scratch using C#, before opening the visual studio and start typing in the keyboard I want to prepare a solid design for my software. The main challenge for me is how to handle errors and exceptions. I know that .Net Framework provide a good error handling but in addition to that I need to increase my software robustness. So i want to know is there any best practices to avoid Software crashing, hanging or freezing ? If I need to develop a separate tool that diagnostic my software what should it be and what should it do ?

closed as too broad by gnat, Robert Harvey, RubberDuck, amon, Doc Brown Mar 15 '18 at 17:44

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 7
    This is too broad. Narrow your question down to a specific, software design-related problem you are having. – Robert Harvey Mar 15 '18 at 15:17
  • Are you asking about how to test software? – Erik Eidt Mar 15 '18 at 15:20
  • If we limit the question to handle errors it's fine, how to ensure software robustness is too broad however. – Walfrat Mar 15 '18 at 16:08
6

handle errors and exceptions

Handle the exceptions you can recover from. Send up the ones you can't.

A file not being found is a problem but does it need to destroy all the work the user has done? Just tell them they couldn't load what they were trying to load. On the other hand if an exception leaves the system in some weird state don't make things worse by catching it and pretending things are fine when they aren't. If you can't predict what happens next roll over and die.

best practices to avoid Software crashing, hanging or freezing

Do not leak memory.

What makes server software developers so amazing is their ability to create software that can run for months without needing a restart. What makes linux systems so amazing is their ability to run for months without needing a restart.

If you leak memory your software is not amazing. It will need a restart. Even in c# this can happen. Sure it's got a garbage collector but all you have to do is hold a reference to something for longer than you need and it's a leak. The garbage collector won't help you here. If this thing is created "as needed" you're in big trouble because you're going to keep making more of it and never throw the old crap out.

The stupid easy way to detect some of these leaks is to watch your app run in the task manager. What does it's memory usage do over time?

If I need to develop a separate tool that diagnostic my software what should it be and what should it do

Test.

Automated tests. Unit tests, integration tests, end-to-end tests. Manual tests. Just test. Testing is a very intimate thing so don't expect anything you buy to just magically solve this problem for you. This is work. It's just as much work, if not more, as making the application itself. But it pays off.

1

Look at exceptions.

A general strategy would be

  • when an error occurs log it; write it to a file or error database. This is useful for monitoring your application and diagnosing faults

  • if it is recoverable; then recover. Ensure your system is in a sane state and continue. This may involve discarding some transaction or packet. If it might be a problem log it.

  • if it isn't recoverable; allow the user to save his work and do a clean shutdown

Carrying on after the system is broken only compounds the problem.

There is no "error handling strategy" that enables recovery from bugs. Your developement process should have elimated them before the user got near your system.

There are static analysis tools and testing tools to help you find problems in your code.

Not the answer you're looking for? Browse other questions tagged or ask your own question.