Building an error-submission system for AJAX applications

Source: Internet
Author: User
Tags wrapper

Summary when some applications crash, they often give the user an opportunity to submit information about the error. This information can help developers track and fix bugs. This article will show you how to implement this functionality in your Javascript/ajax application.

First, the introduction

If you can access the end user's computer, the end user's JavaScript error is easy to debug. Now that you can't do this, you can take the following steps: Ask the user to send you what you need to fix the problem.

When applications like Mozilla browser crash, they start an error-submitting program. These programs will ask the user if they want to submit an error report. If the user wants to, the program will ask them to enter as much information as possible about the crash of their program. This information, together with the error-submitting program's own profiling data, is submitted to the email center so that developers and engineering managers can read the analysis.

This functionality is extremely useful for developers. Now that the program is running on the client machine, this is the only way to get the same error message that developers cannot regenerate on their own development systems. They can also monitor the frequency and severity of the particular error to determine which errors should be corrected first.

This article will show you how to support this error-submission feature in the Javascript/ajax program. When an error occurs in your code, the system pops up a window in which the user can submit an error message.

Ii. issues

How do I install a user error-submission program in my Javascript/ajax application?

Third, answer

Put the code in a wrapper that allows the user to submit an e-mail message with a detailed error message.

(i) Catch errors

The following files are included in the corresponding download source code in this article, and you can use them to implement the above solution:

talkback.js-This file includes the complete source code of the system

test.html-A sample script that uses Talkback.js to handle a discovery error

The test.html page here contains some JavaScript code that throws an exception. This page installs the function fun_a () as the OnLoad processor in the body section. The fun_a () function calls Fun_b () again, and Fun_b () calls Fun_c (). Finally, Fun_c () accesses a nonexistent domain in an object that does not exist and triggers a real JavaScript exception.

First, you need to capture this error before the user can see it. In this way, you can give the user an opportunity to submit an error message, but you don't want him or her to see anything else. Our goal is to minimize the content that this error exposes to the user.

This is very easy to achieve. Assume that the main program can be activated through the following functions:

function fun()
{
 //程序在此.
}
fun = tb_wrap( fun);

Note the invocation of Tb_wrap () here. This allows the fun () function to be placed in a wrapper that captures any exceptions and processes them. Also, the user will not see any exceptions that occur in fun ().

(ii) collection of error messages

Once you have caught the error, you need to extract as much information as possible. The more error data you send back to the developer, the more likely they are to discover and fix the error.

Unfortunately, the Error object has different properties depending on which browser the user is running. In most cases, you can rely on the name and message properties. Note that the Stack property contains an extremely useful stack trail, except that it is available only in the most recent version of the Mozilla based browser.

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.