Some methods inside the .Net Framework make an exception if it does not have a good format.
A good example is int.TryParse(object value)
if your value is "10", this will throw an exception. In this case, we know this because of an incorrect conversion.
So
try { int.TryParse(value); return true; } catch { return false; }
There may be a function that tells us whether a string is a valid interfer.
If you use this form for this question, do not catch (Exception ex), as this makes .Net serialize the error inside an object that is slow.
It is also important to remember that even if you use return inside the catch try block, it will still execute the finally block.
So, if your cleaup code is inside, finally, donโt worry that the infrastructure will invoke it.
My 2 cents. N.
NPayette Mar 03 '10 at 17:47 2010-03-03 17:47
source share