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
介绍Component mFaceBook以帮助在Facebook上注册网站成员资
By wipaporn Wed 13 Feb 2019 3:20 pm Board Chinese Language - 简体中文
0
325
Wed 13 Feb 2019 3:20 pm By wipaporn
介绍Paytoread。插件只显示一些文本。
By wipaporn Wed 13 Feb 2019 3:17 pm Board Chinese Language - 简体中文
0
307
Wed 13 Feb 2019 3:17 pm By wipaporn
介绍插件MD水印(MD水印插件),自动水印插件
By wipaporn Wed 13 Feb 2019 3:15 pm Board Chinese Language - 简体中文
0
1057
Wed 13 Feb 2019 3:15 pm By wipaporn
Introducing Plugin MD Watermark, plug for automatic watermarking
By wipaporn Wed 13 Feb 2019 3:11 pm Board English Language
0
1361
Wed 13 Feb 2019 3:11 pm By wipaporn
Introducing PayToRead. The plugin shows only some text.
By wipaporn Wed 13 Feb 2019 3:08 pm Board English Language
0
1470
Wed 13 Feb 2019 3:08 pm By wipaporn
Introducing Component MFacebook to help with website membership registration with Facebook
By wipaporn Wed 13 Feb 2019 3:06 pm Board English Language
0
1440
Wed 13 Feb 2019 3:06 pm By wipaporn
Introducing Mrelated Article Specific Category Module (Storage browsing history).
By wipaporn Wed 13 Feb 2019 3:03 pm Board English Language
0
1590
Wed 13 Feb 2019 3:03 pm By wipaporn
Introducing Mod MDFiles Categories Module Bring Categories from MDFile.
By wipaporn Wed 13 Feb 2019 2:59 pm Board English Language
0
5333
Wed 13 Feb 2019 2:59 pm By wipaporn
Introducing the Mod MDFile recent module to show files from MDFile
By wipaporn Wed 13 Feb 2019 2:56 pm Board English Language
0
6598
Wed 13 Feb 2019 2:56 pm By wipaporn
Introducing MDFile Components for Joomla, helping to download document files on the website.
By wipaporn Wed 13 Feb 2019 2:49 pm Board English Language
3
2746
Wed 29 Apr 2020 11:49 am By mindphp
Features Review : Components MDFile membantu memuat turun fail dokumen di laman web.
By abdkode Wed 13 Feb 2019 2:37 pm Board Bahasa Language
0
1011
Wed 13 Feb 2019 2:37 pm By abdkode
Features Review : Mod MDFile recent Module yang menunjukkan fail yang diupload
By abdkode Tue 12 Feb 2019 6:45 pm Board Bahasa Language
0
1364
Tue 12 Feb 2019 6:45 pm By abdkode
Features Review : Plugin MD Watermark memudahkan dalam meletakan tanda air atau watermark
By abdkode Tue 12 Feb 2019 4:20 pm Board Bahasa Language
0
731
Tue 12 Feb 2019 4:20 pm By abdkode
这个(Pace)是什么?
By Parichat Wed 06 Feb 2019 7:25 pm Board Chinese Language - 简体中文
0
691
Wed 06 Feb 2019 7:25 pm By Parichat
pace 가 뭐죠?
By Parichat Wed 06 Feb 2019 7:25 pm Board korean Language - 한국어
0
470
Wed 06 Feb 2019 7:25 pm By Parichat
Mindphp webboard 등록하는 방법
By wipaporn Wed 06 Feb 2019 6:12 pm Board korean Language - 한국어
0
128
Wed 06 Feb 2019 6:12 pm By wipaporn
minephp webboard 注册方法
By wipaporn Wed 06 Feb 2019 5:49 pm Board Chinese Language - 简体中文
0
190
Wed 06 Feb 2019 5:49 pm By wipaporn
How to register minephp webboard
By wipaporn Wed 06 Feb 2019 5:30 pm Board English Language
0
362
Wed 06 Feb 2019 5:30 pm By wipaporn
Let's get to know Korea
By wipaporn Mon 04 Feb 2019 8:04 pm Board korean Language - 한국어
0
533
Mon 04 Feb 2019 8:04 pm By wipaporn
Let's get to know China
By wipaporn Mon 04 Feb 2019 8:03 pm Board English Language
0
399
Mon 04 Feb 2019 8:03 pm By wipaporn