JavaScript
  Home arrow JavaScript arrow Page 4 - JavaScript Errors
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

JavaScript Errors
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2008-01-07

    Table of Contents:
  • JavaScript Errors
  • Try...Catch
  • Throwing the Ball (and Exceptions)
  • By the Numbers

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    JavaScript Errors - By the Numbers


    (Page 4 of 4 )

    You could do the above with numbers as well. Say you had a virtual lawn. Maybe you are eighty years old and you wear your pants up to your neck. You probably sit on your virtual porch all day people watching. Maybe some of those people get out of line. Here is a crotchety program to handle just such a situation:


    <html>

    <body>

    <script type="text/javascript">

    var age=prompt("Enter your age whippersnapper:","")

    try

    {

    if(age>21)

    throw "FirstGrump"

    else if(age<21)

    throw "SecondGrump"

    else if(age==21)

    throw "FourthGrump"

    else if(isNaN(age))

    throw "ThirdGrump"

    }

    catch(er)

    {

    if(er=="FirstGrump")

    alert("I remember when I was your age...<falls asleep> zzzzzz")

    if(er == "SecondGrump")

    alert("Pull up your pants! And Get off my lawn!")

    if(er == "ThirdGrump")

    alert("Eh?!? Wassat?!? I didn't here ye")

    if(er == "FourthGrump")

    alert("Let's go get some booze!")

    }

    </script>

    </body>

    </html>



    This program asks the young whippersnapper to enter their age. If the age is greater than 21, an exception is thrown and a pop-up appears saying, “I remember when I was your age <falls asleep> zzzzzz” If the age is less than 21, an exception is thrown that says:”Pull up your pants! And get off my lawn!” If the user inputs 21 as their age, a pop up displays exclaiming: “Let's go get some booze!” Finally, if the user inputs any other data, they will get an alert stating: “Eh?!? Wassat?!? I didn't here ye”

    That concludes this issue. Next episode we will discuss JavaScript Objects and learn how to use them.

    Till then...


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Thanks for stopping by to read my article on JavaScript errors. In this issue we...
     

    JAVASCRIPT ARTICLES

    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget
    - Ajax Hack for Entering Information Without R...
    - EXT JS 2.1 Overview
    - Using the Style Object for Zebra Tables with...
    - Binary Searching
    - An Improved Approach to Building Zebra Tables
    - Assigning Background Colors Dynamically to Z...
    - Building Zebra Tables with CSS and JavaScript
    - JavaScript: Array Objects
    - A Closer Look at Smart Markers with Yahoo! M...
    - Using Polylines and Smart Markers with Yahoo...
    - Bulleted Menu of Links
    - Creating Click Loggers and Basic Markers wit...
    - Adding Pan Controls to Yahoo! Maps







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway