There are some flaws in your code:
-
you should prefer
int.TryParseinstead ofParse. AnExceptionshould be an unexpected behavior, where you have to react in some way. A userinput is not unexpected, you know there’s a chance that the use inputs invalid data which you can/have to validate. -
When you use exceptions, you should not catch all exceptions at once, but some type of exception where you know how to react.
int.Parseitself throws three kind of exceptions (see http://msdn.microsoft.com/de-de/library/b3h1hf19(v=vs.110).aspx), you can get some other ones from the system itself. Your code should catchFormatExceptioninstead of a catch-all. -
anyway, if you just want to fix your code, you can solve your problem with using two seperate
try .. catchblocks with seperated error messages.
solved Make Exceptions work [closed]