The System.Exception class is the generic class where all exceptions go. There are sub-classes for more specific errors like ArgumentException and NotSupportedException. We won't go into all of these in detail, just to let you know that system.exception isn't the only one. We have seen the OverflowException happen and we handled a generic exception. Better code practise dictates that we should handle a more specific error. Here, is where we handle the overflow and the generic with two Catch blocks.
|<script language="vb" runat=server>|
Sub multiply(sender as object, e as system.eventargs)
lbl.Text = CInt(num1.Text) * CInt(num2.Text)
Catch excp as system.overflowexception 'Catch overflow errors
lbl.Text = "Those numbers are too large"
Catch excp as System.Exception 'Catch any other error
lbl.Text = "An error has occurred"
Now, you can get the overflow error and if you want to get the other one, try entering in some letters into one of the text boxes.