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



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"
End Try
End Sub

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.

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:36:38 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search