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
Does MD Watermark work under Joomla 3.9.20?
By Balazs Thu 16 Jul 2020 4:48 pm Board English Language
6
404
Thu 16 Jul 2020 10:31 pm By Balazs
The program calculates the PMT
By prmindphp Wed 20 May 2020 6:45 pm Board English Language
1
199
Thu 21 May 2020 5:57 pm By prmindphp
Helper for calculating NPER values
By prmindphp Tue 19 May 2020 6:55 pm Board English Language
1
179
Thu 21 May 2020 5:59 pm By prmindphp
Program that will be used for home loan calculations
By prmindphp Mon 18 May 2020 6:49 pm Board English Language
1
204
Thu 21 May 2020 6:02 pm By prmindphp
Tools that will help calculate car tax
By prmindphp Thu 14 May 2020 7:00 pm Board English Language
1
194
Fri 15 May 2020 12:03 am By prmindphp
Helper to create slidershow, Module Product Slide of MooZiiCart
By prmindphp Thu 30 Apr 2020 6:32 pm Board English Language
0
244
Thu 30 Apr 2020 6:32 pm By prmindphp
Helper in searching products by category and keywords with Module Ajax Search of MooZiiCart
By prmindphp Tue 28 Apr 2020 6:17 pm Board English Language
0
212
Tue 28 Apr 2020 6:17 pm By prmindphp
Helper to restore the system to clear data, Plugin System MRestore
By prmindphp Fri 24 Apr 2020 7:05 pm Board English Language
0
200
Fri 24 Apr 2020 7:05 pm By prmindphp
Creating social share buttons, share the website's content to Social Media With Plugin Content Msocial
By prmindphp Wed 22 Apr 2020 7:05 pm Board English Language
0
191
Wed 22 Apr 2020 7:05 pm By prmindphp
Create Content Marketing and Product with Content Product Match of MooZiiCart
By prmindphp Tue 21 Apr 2020 7:19 pm Board English Language
0
229
Tue 21 Apr 2020 7:19 pm By prmindphp
Filtering for find the product with Module Filter product of MooZiiCart
By prmindphp Thu 09 Apr 2020 6:51 pm Board English Language
0
223
Thu 09 Apr 2020 6:51 pm By prmindphp
Template Megadeal of MooZiiCart for creating websites to sell products online
By prmindphp Fri 03 Apr 2020 6:45 pm Board English Language
0
390
Fri 03 Apr 2020 6:45 pm By prmindphp
[MooZiiCart] [Module] Displaying products that customers are interested by Wishlist Module
By prmindphp Fri 27 Mar 2020 5:46 pm Board English Language
0
591
Fri 27 Mar 2020 5:46 pm By prmindphp
Show the Bestsellers Product by Module Bestseller
By prmindphp Wed 25 Mar 2020 6:04 pm Board English Language
0
403
Wed 25 Mar 2020 6:04 pm By prmindphp
Show Products Category by Module Category
By prmindphp Tue 24 Mar 2020 6:07 pm Board English Language
0
490
Tue 24 Mar 2020 6:07 pm By prmindphp
Plugin System MZC Auto Close to enable the open and close odering system
By prmindphp Wed 19 Feb 2020 6:38 pm Board English Language
0
3092
Wed 19 Feb 2020 6:38 pm By prmindphp
MDPartner Component for store client data in CRM system
By prmindphp Sat 25 Jan 2020 3:04 pm Board English Language
0
862
Sat 25 Jan 2020 3:04 pm By prmindphp
i am looking for help
By Anonymous Tue 14 Jan 2020 5:46 pm Board English Language
1
894
Tue 14 Jan 2020 6:03 pm By noppadonsk
Dot Net Training
By Poonaam Fri 10 Jan 2020 2:20 pm Board English Language
0
1138
Fri 10 Jan 2020 2:20 pm By Poonaam
MDRental, Area management assistant for rental business
By prmindphp Wed 08 Jan 2020 6:51 pm Board English Language
0
878
Wed 08 Jan 2020 6:51 pm By prmindphp