catch{} butterfingers {}


P

Peter Morris

Hi all, I have a perplexing problem....

protected void ArticleFormView_ItemUpdating(object sender,
FormViewUpdateEventArgs e)
{
try
{
//Next line is line 36
if (!ArticleDataSource.IsValidNewValues(e.Keys, e.NewValues))
e.Cancel = true;
}
catch (FormatException)
{
e.Cancel = true;
Page.Validators.Add(new StaticValidator("Invalid price"));
}
}

As you can see I am catching FormatException. I put a breakline on line 36
and when I hit F10 ArticleDataSource.IsValidNewValues will throw a
FormatException. At this point I would expect my Catch to kick in, but as
you can see from the following exception information it is not. Does anyone
know why this is?


Thanks

Pete


Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct
format.

Source Error:

Line 34: try
Line 35: {
Line 36: if (!ArticleDataSource.IsValidNewValues(e.Keys, e.NewValues))
Line 37: e.Cancel = true;
Line 38: }


Source File:
C:\OtherData\CapableObjects\docs\QuickStart\VS2005\SourceCode\07\QuickStart.Asp\Members\EditArticle.aspx.cs
Line: 36

Stack Trace:

[FormatException: Input string was not in a correct format.]
System.Number.StringToNumber(String str, NumberStyles options,
NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2755599
System.Number.ParseDecimal(String value, NumberStyles options,
NumberFormatInfo numfmt) +138
System.Decimal.Parse(String s, NumberStyles style, IFormatProvider
provider) +37
System.ComponentModel.DecimalConverter.FromString(String value,
NumberFormatInfo formatInfo) +36
System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext
context, CultureInfo culture, Object value) +335

[Exception: 2.5sd is not a valid value for Decimal.]
System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext
context, CultureInfo culture, Object value) +398
System.ComponentModel.TypeConverter.ConvertFrom(Object value) +54
Eco.Web.UI.WebControls.EcoDataSourceView.ApplyValues(IObjectInstance obj,
IDictionary values) in
c:\dev\fbuild\source\Public.CLR\Handles\Asp\EcoDataSourceView.cs:780
Eco.Web.UI.WebControls.EcoDataSourceView.IsValidNewValues(IDictionary
keys, IDictionary values) in
c:\dev\fbuild\source\Public.CLR\Handles\Asp\EcoDataSourceView.cs:750
Eco.Web.UI.WebControls.EcoDataSource.IsValidNewValues(IDictionary keys,
IDictionary values) in
c:\dev\fbuild\source\Public.CLR\Handles\Asp\EcoDataSource.cs:892
QuickStart.EditArticle.ArticleFormView_ItemUpdating(Object sender,
FormViewUpdateEventArgs e) in
C:\OtherData\CapableObjects\docs\QuickStart\VS2005\SourceCode\07\QuickStart.Asp\Members\EditArticle.aspx.cs:36
 
Ad

Advertisements

P

Peter Morris

First System.FormatException is thrown. Then it appears that this is caught
and thrown as an InnerException of a System.Exception (what a poor choice).

So I have
System.Exception
InnerException = System.FormatException

The ASPX shows the inner exception (FormatException) so

catch (FormatException)

will not catch it, I need

catch
{
...etc...
}


Not impressed :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top