Exceptions in ASP.NET
page 2 of 4
by . .
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 21856/ 51



An exception is an error. Its not a compile time error though, but a runtime error. Runtime errors are ones that don't occur at compile-time because they aren't anticipated to happen. The best way to show you this is through an example. Here, is a simple page that does multiplication. Try it out. You'll see that it can multiply to some degree of accuracy. Now enter in two numbers larger than 2147483647 and -2147483647. You get an exception like the one below.

Exception of type System.OverflowException was thrown.

This happens because integers only can store numbers below 2147483647 and above -2147483647. I converted the numbers to Integers beforehand if you ask why I didn't use a larger storage medium. The same error would have occurred with a Double or Decimal. When the program came across these large numbers it gave up and threw an exception. Here is the code for the page -

<script language="vb" runat=server>

Sub multiply(sender as object, e as system.eventargs)

lbl.Text = CInt(num1.Text) * CInt(num2.Text)

End Sub

<form runat=server>
<asp:textbox id="num1" runat=server ontextchanged="multiply"/> x <asp:textbox id="num2" runat=server ontextchanged="multiply"/> = <asp:button runat=server/><p><asp:label id="lbl" runat=server/>

View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2023 ASPAlliance.com  |  Page Processed at 2023-04-01 6:38:56 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search