Microsoft ASP. NET Ajax framework (6) debugging and typed errors

Source: Internet
Author: User
Vs2008

This article describes how to output debugging information when developing the client JavaScript, and how to define and capture custom exception types.

1. SYS. debug
the Microsoft Ajax Library provides a sys. the debug class is used to output debugging information during debugging. With this class, we no longer need to use the lame alert method.
to display debugging tracing information on the page, you must add a textarea control named traceconsole on the page. textarea id = " traceconsole " Cols = " 50 " rows = " 10 " > textarea >

1.1 sys. debug. trace
method definition sys. debug. trace (text)
the function of this method is to display sys. debug. trace ( " This is a debug message " );

after the page is executed, the text is displayed in the traceconsole.
1.2 sys. debug. tracedump
method definition sys. debug. tracedump (object, string name)
the function of this method is to set all attributes (including values) of an object) show in traceconsole
assume that there is an element named "form1" on my page, sys. debug. tracedump (sys. UI. domelement. getlocation ($ Get ( " form1 " )));

In the traceconsole, I will see the following information:
Tracedump {SYS. UI. Point}
X: 10
Y: 15

1.3 SYS. Debug. Assert
Method definition SYS. Debug. Assert (Boolean condition, string message, Boolean displaycaller)
That is, our common assertions in unit test. When the condition is false, the script execution ends abnormally and the message is displayed. If displaycaller is true, the caller (function) to which the assertion belongs will be displayed)

SYS. Debug. Assert ( 1 > 2 , " How can 1 be greater than 2? " , False );

A Windows warning box pops up with a message.

2. Exceptions and try... catchCodeBlock
2.1 use the built-in exception type

Several methods under error can help us create several common built-in exception types
Example: Try   {
ThrowError. argumentnull ();
}

Catch (E) {
SYS. Debug. tracedump (E );
}

The output information in the traceconsole is:
Tracedump {error}
Description: SYS. argumentnullexception: value cannot be null.
Message: SYS. argumentnullexception: value cannot be null.
Name: SYS. argumentnullexception
Paramname: Undefined

2.2 Use a custom exception type
You can use create in error to customize the exception type: VaR myerror = Error. Create ( " Myerror " , {Name:"Xxx", Desc:"My CC"} );
Try   {
ThrowMyerror;
}

Catch (E) {
SYS. Debug. tracedump (E );
}


Traceconsole output:

Tracedump {error}
Description: myerror
Message: myerror
Name: XXX
Desc: My CC

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.