0

It was firs time I have used delegate and event. I made an error handler event for Memory Game program. The program has a "lot" of SQL operation. The event functioning wery well. I subscribe a MessageBox "caller void" to print errormessages out in the Main Form. (It was a surprise for me that I had to subscribe this printout void only in the Main and every Form errors are printed out by this little void.)

I have problem with error handling. When I handled the problems with Exceptions I could handle everything to the very end (if Exception not null do....).

Delegate and event is very usefull but I dont know how close the actual form or simply make something to do when an error happens.

I have tried to implement this.close() after MessageBox printed out the message but it closes the whole program.

     private void MessageBoxPopUp(string errorMessageForMessageBox)
     {
         MessageBox.Show(errorMessageForMessageBox);
         this.Close();
     }

I would like to close the form parented by the main form or I want the program just do nothing. Now The messageBox ("Game saved succeddfully.") pops up after an error message because it is written under the void calling the errorMessage event. With Exception and braces I could separate the different derivations.

Thank you for help,

2
  • you could set a global variable with true which get checked in the messageBox function. If an error occures set the variable to false and the messageBox do not pop up.
    – Mar Tin
    Jun 14, 2019 at 10:43
  • I used this solution you suggested. I am thinking about an event that would be invoked when the errorMessage stopped its task. Anyway, thanks a lot.
    – Brokkoli
    Jun 14, 2019 at 14:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.