Exception Handling
-
Hi, I am trying to catch a user exception. The user presses two buttons. But the second button should only be pressed if the first one has else i should warn the user of an incorrect action. any ideas> kash
Hmmmm, I wouldn't consider that an "exception" per se... I see an "exception" as an error that occurs programatically, like a FileNotFound or the like. This is more of a UI issue. Anyway, I would simply set a bool value somewhere in your code, inside the Form class if you are using Windows Forms for example. Upon program initialization, set the bool to false. Everytime the user presses the first button, set the bool to true. When the user presses the second button, check whether the bool is true. If it isnt, show the user a MessageBox or echo the error somewhere where the user is gonna see it. Hope this helps.
-
Hmmmm, I wouldn't consider that an "exception" per se... I see an "exception" as an error that occurs programatically, like a FileNotFound or the like. This is more of a UI issue. Anyway, I would simply set a bool value somewhere in your code, inside the Form class if you are using Windows Forms for example. Upon program initialization, set the bool to false. Everytime the user presses the first button, set the bool to true. When the user presses the second button, check whether the bool is true. If it isnt, show the user a MessageBox or echo the error somewhere where the user is gonna see it. Hope this helps.
-
Hi, I am trying to catch a user exception. The user presses two buttons. But the second button should only be pressed if the first one has else i should warn the user of an incorrect action. any ideas> kash
Kash wrote: But the second button should only be pressed if the first one has Then disable the second button until after the user pressed the first. John
-
Hi, I am trying to catch a user exception. The user presses two buttons. But the second button should only be pressed if the first one has else i should warn the user of an incorrect action. any ideas> kash
John D. has provided you with the correct solution. If a control is not supposed to be interacted with until a certain condition exists, then disable the control, period. Don't clutter your code with variables that just makes maintenance harder. It sounds great now, but you must always consider the code in the future.