Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

catch{} butterfingers {}

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter Morris - 13 Mar 2008 18:48 GMT
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
Peter Morris - 13 Mar 2008 19:16 GMT
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 :-)

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.