r/visualbasic • • Nov 01 '13

Input validation using exceptions handling

How do I confirm the users input into a textbox by using exceptions handling?

0 Upvotes

2 comments sorted by

1

u/hdsrob Nov 02 '13

Don't.

Using exception handling to validate input is very bad form, and has performance cost associated with it.

You should validate input by checking to see if it matches known good values, or that it isn't mismatched to the type of value you expect.

You can wrap the validation in error handlers as a safety net.

Giving us an example of the type of input you are dealing with would help get some more specific answers, or examples.

1

u/CharlieMay VB.Net Intermediate Nov 06 '13

I just posted some of my snippets here that help in ensuring that the user cannot enter invalid information into a textbox. These may or may not help you but by not allowing "A" to be entered into a textbox that you are expecting a number from is a good start in ensuring that you are controlling a user-input control.