User Rating: 1 / 5

Star ActiveStar InactiveStar InactiveStar InactiveStar Inactive
 

Error may have problems of JavaScript code bug caused by incomplete code. Or the introduction of some type of code to use. As a result, when you put these code used to achieve Error on the page. Pop up window with a warning that JavaScript Error resulting in a slower site. Information on the page is loading slowly. JavaScript problem because the load

 

One feature of object-oriented programming language is there. The trap and handle the error occurred. JavaScript also has this feature using try-catch mechanism as well as object oriented programming language to another.

 

1.try catch statement

   Java code to write the script . If we want to trap any errors . That occur during the execution of code outside the function. Or code in the function (Under the {} ) can be done by using the try {} enclose that area . This is because the {} are used to define a function or command . Thus we can not mold car enclosed area overlaps with the functions in the function or cross section surrounded a group command. (Must be enclosed area outside the function Or within areas Function must be framed across the command group to the series .

Syntax: 

   {
   / / Run some code here 
   } 
catch (err) 
   {
   / / Handle errors here 
   } 

    When an error occurs during the operation, according to a statement in the try {}, the program will jump to work within the catch () {} The data tells a mistake to send the stored variable in parentheses after the reserved word catch. 

Example:

<html>
<head>
<script>
var txt="";
function message()
{
try
  {
  adddlert("Welcome guest!");
  }
catch(err)
  {
  txt="There was an error on this page.\n\n";
  txt+="Error description: " + err.message + "\n\n";
  txt+="Click OK to continue.\n\n";
  alert(txt);
  }
}
</script>
</head>
<body>
<input type="button" value="View message" onclick="message()" />
</body>
</html>

 This is the result:

 

In some cases, we can predict that. May be due to malfunction in any way, it does. Instead trap in the programmers alone. We may write code to create faulty signal the event itself with. And by creating an event that this error . We can tell the type attached with the particular errors . In the response to the error in the catch () {} , we are able to report information error checking and responding specifically to. Error signal is recognized .

 

2. Statement is a statement that can throw Exception if used in conjunction with a try .. catch statement to make to control the direction of the work. And set the appropriate error message to the error. 

Creating a signal error. We throw done using reserved words as an example.

Example:

<html>
<body>
<script type="text/javascript">
var x=prompt("enter a number between 0 and 10:","")
try
{
if(x>10)
throw "Err1"
else if(x<0)
throw "Err2"
}
catch(er)
{
if(er=="Err1")
alert("Error! The value is too high")
if(er=="Err2")
alert("Error! The value is too low")
}
</script>
</body>
</html>
 

This is the result:

When you enter a non-prompted error by 0-10 below.

It can be seen that in this case, we generate the error by directing the data as "Err1" or "Err2" based on the state we want and in the catch () {} to see that the variable er the data show . mistake We will keep the cast (throw) signals this error . Er , we can check the value in response to a particular fault cases .

For older browsers do not support it but to support the try-catch error trapping through the onerror ( versions of popular web browsers used today to support both) .

Recent Topics
Subject
Post Reply
Open
Recent
使用 Module M Slideshows 说明手册
By wipaporn Wed 20 Feb 2019 4:56 pm Board Chinese Language - 简体中文
0
20443
Wed 20 Feb 2019 4:56 pm By wipaporn
使用 Component M Multisite Master 说明手册
By wipaporn Wed 20 Feb 2019 4:30 pm Board Chinese Language - 简体中文
0
19986
Wed 20 Feb 2019 4:30 pm By wipaporn
使用 Component M Multisite Client 说明手册
By wipaporn Wed 20 Feb 2019 4:06 pm Board Chinese Language - 简体中文
0
20838
Wed 20 Feb 2019 4:06 pm By wipaporn
Features Review : M MultiSite Content client Komponen untuk merekodkan Nama Domain Master Site
By abdkode Wed 20 Feb 2019 3:51 pm Board Bahasa Language
0
8084
Wed 20 Feb 2019 3:51 pm By abdkode
使用Module MDFiles Popular 说明手册
By wipaporn Wed 20 Feb 2019 3:35 pm Board Chinese Language - 简体中文
0
24378
Wed 20 Feb 2019 3:35 pm By wipaporn
Features Review : MDFiles Documents membantu menghubungkan artikel ke Component MDFiles
By abdkode Wed 20 Feb 2019 3:33 pm Board Bahasa Language
0
4714
Wed 20 Feb 2019 3:33 pm By abdkode
使用 Module MDFiles Featured 说明手册
By wipaporn Wed 20 Feb 2019 3:04 pm Board Chinese Language - 简体中文
0
25157
Wed 20 Feb 2019 3:04 pm By wipaporn
使用Module MDFiles Categories 说明手册
By wipaporn Wed 20 Feb 2019 2:31 pm Board Chinese Language - 简体中文
0
21915
Wed 20 Feb 2019 2:31 pm By wipaporn
使用 Module MDfiles recent 说明手册
By wipaporn Wed 20 Feb 2019 2:29 pm Board Chinese Language - 简体中文
0
24132
Wed 20 Feb 2019 2:29 pm By wipaporn
使用Component MDFiles说明手册
By wipaporn Wed 20 Feb 2019 12:10 pm Board Chinese Language - 简体中文
0
10817
Wed 20 Feb 2019 12:10 pm By wipaporn
使用 Component MJForm 说明手册
By wipaporn Wed 20 Feb 2019 12:03 pm Board Chinese Language - 简体中文
0
23220
Wed 20 Feb 2019 12:03 pm By wipaporn
Features Review : Plugin Editors XTD Multicontent untuk mengeluarkan artikel dari Master Site ke Web Clien
By abdkode Tue 19 Feb 2019 6:52 pm Board Bahasa Language
0
6516
Tue 19 Feb 2019 6:52 pm By abdkode
Features Review : Mod MDFiles Popular modul menyenaraikan fail popular
By abdkode Tue 19 Feb 2019 5:41 pm Board Bahasa Language
0
5472
Tue 19 Feb 2019 5:41 pm By abdkode
Features Review : Mod MDFiles Featured memaparkan fail-fail yang dipilih dari MDFile untuk dipaparkan pada Joomla
By abdkode Tue 19 Feb 2019 4:39 pm Board Bahasa Language
0
2777
Tue 19 Feb 2019 4:39 pm By abdkode
Features Review : Components Mjform komponen untuk membuat borang laman web
By abdkode Tue 19 Feb 2019 3:23 pm Board Bahasa Language
0
2657
Tue 19 Feb 2019 3:23 pm By abdkode
Mod MDFiles Popular 모듈 소개 MDFile에서 파일을 가져와 표시
By wipaporn Fri 15 Feb 2019 6:06 pm Board korean Language - 한국어
0
6470
Fri 15 Feb 2019 6:06 pm By wipaporn
MDFiles Featured modules를 소개하면 MDFile에서 파일을 가져와 보여준다.
By wipaporn Fri 15 Feb 2019 6:06 pm Board korean Language - 한국어
0
6102
Fri 15 Feb 2019 6:06 pm By wipaporn
마스터 사이트에서 Web Client로 문서를 끌어오기 위한 플러그인인 Editors XTD Multicontent를 소개한다.
By wipaporn Fri 15 Feb 2019 5:48 pm Board korean Language - 한국어
0
2034
Fri 15 Feb 2019 5:48 pm By wipaporn
Joomla 1.5를 Joomla 2.5, 3.X로 업그레이드하기 위한 MJUpgrade 소개
By wipaporn Fri 15 Feb 2019 5:36 pm Board korean Language - 한국어
0
2397
Fri 15 Feb 2019 5:36 pm By wipaporn
MApplication Form Components를 소개한다. 구직 신청서는 웹사이트를 통해 작성된다.
By wipaporn Fri 15 Feb 2019 5:27 pm Board korean Language - 한국어
0
2225
Fri 15 Feb 2019 5:27 pm By wipaporn