Exceptions?
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 -
<html> <body> <script language="vb" runat=server>
Sub multiply(sender as object, e as system.eventargs)
lbl.Text = CInt(num1.Text) * CInt(num2.Text)
End Sub
</script> <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/> </form> </body> </html> |