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
Program convert area
By prmindphp Wed 27 Nov 2019 11:26 am Board English Language
0
137
Wed 27 Nov 2019 11:26 am By prmindphp
Program exchange rate - Information form Bank of Thailand API
By prmindphp Tue 26 Nov 2019 2:34 pm Board English Language
0
121
Tue 26 Nov 2019 2:34 pm By prmindphp
Tracking Thailand Post Program
By prmindphp Mon 25 Nov 2019 5:47 pm Board English Language
0
155
Mon 25 Nov 2019 5:47 pm By prmindphp
Square Root Calculate Program
By prmindphp Fri 22 Nov 2019 11:30 am Board English Language
0
204
Fri 22 Nov 2019 11:30 am By prmindphp
The program calculates the mean, the variable, the standard deviation
By prmindphp Fri 22 Nov 2019 11:12 am Board English Language
0
176
Fri 22 Nov 2019 11:12 am By prmindphp
Introducing the new Mindphp.com Webboard system function (phpbb v.3.2)
By numtan5839 Tue 19 Nov 2019 6:06 pm Board English Language
0
178
Tue 19 Nov 2019 6:06 pm By numtan5839
The most popular currency pairs in the Forex for new traders
By numtan5839 Mon 18 Nov 2019 5:32 pm Board English Language
0
157
Mon 18 Nov 2019 5:32 pm By numtan5839
BIG DATA and Hadoop
By Inglejyoti Mon 18 Nov 2019 4:03 pm Board English Language
0
248
Mon 18 Nov 2019 4:03 pm By Inglejyoti
The most popular currency in the Forex
By numtan5839 Mon 18 Nov 2019 3:24 pm Board English Language
0
143
Mon 18 Nov 2019 3:24 pm By numtan5839
How to use the SQRT function in Excel
By numtan5839 Mon 18 Nov 2019 2:46 pm Board English Language
0
186
Mon 18 Nov 2019 2:46 pm By numtan5839
Deposit money into account with Thailand Post by Bank@post service
By numtan5839 Mon 18 Nov 2019 11:42 am Board English Language
0
305
Mon 18 Nov 2019 11:42 am By numtan5839
Benefits and applications of moving averages
By numtan5839 Mon 18 Nov 2019 10:47 am Board English Language
0
168
Mon 18 Nov 2019 10:47 am By numtan5839
Moving Average
By numtan5839 Sat 16 Nov 2019 2:45 pm Board English Language
0
159
Sat 16 Nov 2019 2:45 pm By numtan5839
weighted arithmetic mean
By numtan5839 Sat 16 Nov 2019 11:56 am Board English Language
0
127
Sat 16 Nov 2019 11:56 am By numtan5839
Digital Marketing Training in Mumbai
By Kanchaan Fri 15 Nov 2019 6:10 pm Board English Language
1
789
Fri 06 Dec 2019 3:16 pm By benjamin28
Thailand Post appease e-commerce with ePacket service
By numtan5839 Fri 15 Nov 2019 5:59 pm Board English Language
0
292
Fri 15 Nov 2019 5:59 pm By numtan5839
The character that precedes Tracking Number - Thailand Post Track & Trace
By numtan5839 Fri 15 Nov 2019 5:09 pm Board English Language
0
132
Fri 15 Nov 2019 5:09 pm By numtan5839
downloading MD Watermark
By bfred Fri 04 Oct 2019 3:21 pm Board English Language
6
1322
Mon 30 Dec 2019 7:26 pm By mindphp
Features Review : Component Mjform Advance untuk meningkatkan form atau borang untuk laman web dgn lebih baik
By abdkode Mon 22 Apr 2019 6:51 pm Board Bahasa Language
0
9341
Mon 22 Apr 2019 6:51 pm By abdkode
Features Review : Mhosting Components untuk mengumpul Packet hosting
By abdkode Mon 22 Apr 2019 6:50 pm Board Bahasa Language
0
1834
Mon 22 Apr 2019 6:50 pm By abdkode