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

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

</script>

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

Try

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

Catch [var] as [thing to catch]

'Handle the problem here

Finally

'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-2021 ASPAlliance.com  |  Page Processed at 2021-02-27 10:05:19 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search