Try catch blocks only catch specific errors during runtime unless you use a keyword such as `throw()` to throw an error.
You have to rework your logic for your desired output to work.
What you should do is check if the access code is actually an integer, if not assign your text removing the error handling all together.
Although you are defiantly not using try,catch,throw properly. I suggest reading up on it.
Also you seem to have stray braces near your last chunk of code before the catch, does this application even compile?
The easiest way to check for stray input is to simply convert your string into an integer and do a wide logic check on it as follows:
Code
if(int.parse(txtInputCode.Text) <= 0 && int.parse(txtInputCode.Text)i >= 9999) {
//output error.
}
Although this in itself may cause a runtime error which will need to be caught depending on the conversions function process of handling non integer input.
Quote (Minkomonster @ Oct 12 2014 11:08pm)
int.parse will through a FormatException if he tries to parse a string that isn't an int. In which case, his try catch will work. It just isn't very good design. His real problem is the logic he is implementing in his if-else chain. That needs to be reworked.
He brings up a good point and the correct function to call to attempt to make this work.
This post was edited by AbDuCt on Oct 12 2014 09:12pm