Trapping Exception, yet system exception is still generated?

Trapping Exception, yet system exception is still generated?

Post by Q1NoYXJwW » Thu, 06 May 2004 03:36:04


I have the following code and when the exception is raised the OS displays a *** Stop dialog box
it says an unhandled exception occured, gives 3 buttons to click details, contintue Quit... i do not want this ugly thing to display, what am i missing from the code below? am i not catching that exception and displaying my own error message? so why is the other one coming up after mine

public bool isInteger(string str

int i=0
bool res=false
if (str != null)

try

i = Int32.Parse(str)
res = true
}
catch (FormatException e)

MessageBox.Show("Make sure to input only numeric values");

}
return res
}
 
 
 

Trapping Exception, yet system exception is still generated?

Post by Trevo » Thu, 06 May 2004 04:30:58


a *** Stop dialog box
contintue Quit... i do not want this ugly thing to display, what am i
missing from the code below? am i not catching that exception and displaying
my own error message? so why is the other one coming up after mine?

MSDN says this method can throw a FormatException, ArgumentNullException,
ArgumentException, FormatException, OverflowException. You only handle
FormatException. To fix your problem catch ANY exception that may be
thrown. As you have found out, one cannot assume that the only exception
that will ever be thrown by this method is a FormatException.

 
 
 

Trapping Exception, yet system exception is still generated?

Post by Christophe » Thu, 06 May 2004 04:44:43

The code only catches FormatException, any other will be forwarded up the
call stack.
OverflowException is another exception that can be raised by the Parse
method, is this the one you are getting?

Chris



a *** Stop dialog box
contintue Quit... i do not want this ugly thing to display, what am i
missing from the code below? am i not catching that exception and displaying
my own error message? so why is the other one coming up after mine?
 
 
 

Trapping Exception, yet system exception is still generated?

Post by Q1NoYXJwW » Thu, 06 May 2004 05:01:05

Ahhh ok, i get it now, we catch all the exceptions instead of just one
Ok thanks for the help