First, you can use
TryParse
instead of
Parse
.
There is nothing difficult in using
try
/
catch
. Moreover, programming without using of structured exception handling makes little sense.
Using exceptions with UI correctly is something special. Please see this:
How do i make a loop that will stop when a scrollbar reaches the bottom[
^].
You can (and often) should parse exception locally as well. The pattern is very simple:
try {
Evaluate();
} catch (System.Format e) {
ShowFormatProblem();
} catch (System.ArithmeticException e) {
ShowException();
}
Pay attention: it will only catch few exception classes:
System.Format
,
System.Arithmetic
exceptions and derived classes. All other exception will propagate top of the stack and will be caught in the level of
Application
(
System.Windows.Forms
or WPF, see the above reference).
It is very important not to block exception from propagation. Your case in one of the rare cases when you can block it for just a few exception classes. It it even much more rare case when you catch and block all exceptions silently; usually this is done to work around some software defect in third-party software not accessible for patching.
—SA