Hi guys, I'm trying to handle an exception but getting some difficulties in its design. Lets say I have a static class:
Code:class StaticQuery { public static void method1() { try { // some code here } // end try catch(InvalidOperationException e1) { // Some error handling code here } }// end method }// end class.
The above works fine, if some code in the try clause generates an Invalidoperation exception, the catch clausee will kick in and execute.
My problem is when using this class. Let's say I have 2 forms: Form1, Form2 (this is just a small example but it highlights my problem).
Code in Form1:
Code in Form2:Code:try { StaticQuery.method1 } catch(Invalidoperationexception) { MessageBox.show("A certain message"); }
Code:try { StaticQuery.method1 } catch(Invalidoperationexception) { MessageBox.show("A different message will be displayed."); }
So in another class or a form, I"m calling this method and when the invalidoperationexception is thrown, I want it to be handled by that form (form1, form2) and not the static class (staticquery). But its not like I could take it out of the static class since there are many other classes that use the method and needs that invalidoperationexception.
I hope I explained myself clearly, could anyone help me, I think its a problem of design, but I could be wrong.
Jennifer.




Reply With Quote