Javascript ASP tutorial error handling

Source: Internet
Author: User

The asperror object has zero (0) methods, nine (9) properties, zero (0) events, and zero (0) collections.

Aspcode
Aspdescription
Category
Column
Description
File
Line
Number
Source

The way you access the asperror properties is with a server method. Yeah, I know; it doesn't make sense. Start with something like VaR myerror = server. getlasterror () And then you can access all nine asperror properties following this pattern: <% = Myerror. Line %> .

below is the script for Lesson 15.

<% @ Language = "JavaScript" %> <! -- Metadata type = "typelib" file = "C: \ Program Files \ common files \ System \ ADO \ msado15.dll" --> <% Try {response. write ("<strong> use <I> getlasterror () </I> <br> </strong> \ r") myerror = server. getlasterror () response. write ("myerror. line: "+ myerror. line + "<br> \ r") response. write ("myerror. file: "+ myerror. file + "\ r") response. write ("<HR> \ r <strong>") response. write ("now an intentional error... ") response. write ("<br> </strong> \ r") myerror = erver. getlasterror () // This line causes an errorresponse. write ("myerror. line: "+ myerror. line + "<br> \ r") response. write ("myerror. file: "+ myerror. file + "<br> \ r")} catch (mydumberror) {response. write ("there is an error:" + mydumberror) %> <br> graceful error handling goes here (inside the catch Statement ). make it as simple or sophisticated as you like. <br> <HR> <strong> now let's break down the error object. </strong> <br> <% for (var I in mydumberror) {response. write (I + ":" + mydumberror [I] + "<br> \ r")} finally {response. write ("<HR> <strong> let's finish up. </strong> <br> \ r ") response. write ("code inside the <I> finally {}</I> statement") response. write ("executes regardless of error (or lack thereof ). \ r ") response. write ("<I> finally {}</I> is totally optional. ") response. write ("it's a good place for things like Rs. close ()... ") response. write ("which you'll see later on. ")} %>

Click here to run the script in a new window.

Okay, so what happenedOn Error resume next? Sorry, that ain't no JavaScript thing. So, what aboutOnerror? That won't work on the server side. But thanks to some core JavaScript we have some error handling.

The section of script for which you wish to provide error handling goes insideTry {}Statements and the what-to-do in the event of an error goes insideCatch {}Statement. There is alsoFinally {}Statement (Optional). The whole thing is just as gracefulOn Error(In my opinion ).

Not every ASP server allows you access to the asperror object. So, don't be surprised if asperror gives you an error.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.