Catch that error : throw « Language Basics « JavaScript DHTML

Home
JavaScript DHTML
1.Ajax Layer
2.Data Type
3.Date Time
4.Development
5.Document
6.Dojo toolkit
7.Event
8.Event onMethod
9.Ext JS
10.Form Control
11.GUI Components
12.HTML
13.Javascript Collections
14.Javascript Objects
15.Javascript Properties
16.jQuery
17.Language Basics
18.Mochkit
19.Mootools
20.Node Operation
21.Object Oriented
22.Page Components
23.Rico
24.Scriptaculous
25.Security
26.SmartClient
27.Style Layout
28.Table
29.Utilities
30.Window Browser
31.YUI Library
JavaScript DHTML » Language Basics » throw 
Catch that error
   
<HTML>
<HEAD>
<TITLE>Catch that error!</TITLE>
<SCRIPT>
function catchError(errString) {
   try {
      try {
         if (errString == -1)
            throw new Error (-1"errString is -1!");
         else
            throw new Error (0"errString is NOT -1!");
      }
      catch(e) {
         if (e.number == -1)
            return (e.description + " Got this one!");
         else
            throw e;
      
   }
   catch (e){
      return(e.description + " This one not handled here!");
   
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name="theForm">
<INPUT type=text name=errText value="-1">
<INPUT type=button name=btnThrow value="Catch it!" onClick="alert(catchError(document.theForm.errText.value));">
</FORM>  
</BODY>
</HTML>

   
    
    
  
Related examples in the same category
1.Throws error in case of invalid data
2.Throw that error
3.Exception handling with try/catch
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.