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

System.Exception

System.Exception

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)
Try
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
</script>

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-2021 ASPAlliance.com  |  Page Processed at 2021-03-02 11:25:51 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search