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

Handling Exceptions

Handling these Exceptions

Handling these exceptions doesn't take much, all it needs is a try....catch...finally code block. See here as I overcome this error in the same example, try using realy large numbers and it comes up with -

An error has occurred, your numbers may be too large

Now, that error is a bit more useful to the user. Here is its code for it.

<script language="vb" runat=server>

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

Try 'Start try block

lbl.Text = CInt(num1.Text) * CInt(num2.Text) 'Code to try

Catch excp as system.exception 'Catch the exception if the try doesn't work

lbl.Text = "An error has occured, your numbers may be too large" 'Handle the exception

End Try 'End try block

End Sub


Now you should be able to see the try block at work. Here is the syntax for it -


'Code to Try. If try fails you can catch the failure

Catch [var] as [thing to catch]

'Handle the problem here


'Close off any loose ends

End Try

The most common thing for the Catch statement (and the only one we'll be using for this article is Catch excep as System.Exception. Now, lets take a closer look at the System.Exception.

View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 

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

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-02-25 2:47:43 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search