Handling Unexpected Errors - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Handling Unexpected Errors

DissolutionDissolution Posts: 2Member
I have a fairly extensive question about programming that I was hoping someone could answer, or at least point me in the right direction to begin further research.

I'm writing a program in C# which interacts with a user and a source of information. During the program's execution, there are various loops (waiting for and processing user interactions and data changes). At any point during this, though, the data source can have an error (unstable connection to the data).
If this error occurs, I need to pause execution, note the error (and inform the user), then have the program 'go back to the beginning' of it's execution (before the error occurred).

The way I'm doing this now is rather inelegant.
During every loop in the program (and before and after all related functions), it calls a method which checks for a variable (_stop). There is another thread running which monitors the data source, and if an error occurs, it sets _stop = true.
So, if the method sees _stop == true, it sends back 'false', which begins a cascade of 'return false;' through all methods until the program is back at the original loop. It can then wait for the data to become available and resume functioning.

I feel like there must be a more simple and elegant solution to the problem than constantly calling a method to see if it returns false and then returning false all the way through all my loops, but I don't know what it might be (or how to research the problem further).

Do you have any advice for me?
Sign In or Register to comment.