iPower Hosting
 
Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read Web Directory

Go Back   Webmaster Forum > Designing and Developing Websites > Programming > Ajax / Javascript

Ajax / Javascript Discussions and help on Ajax and Javascript coding.

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 03-31-2007, 03:30 AM
Jamesbond Jamesbond is offline
WMG Newcomer
 
Join Date: Mar 2007
Posts: 20
iTrader: (0)
Jamesbond is on a distinguished road
Default Exception Handling

In any programming language, your code will throw a run-time exception when trying to execute an illegal command. One of the most trivial illegal operations you may attempt is accessing a null object. Your operating system will definitely complain when trying to access a null object. Accessing an array element that is out of the array's legal range is another example.

More often than not, you want to avoid system errors. System messages are usually cryptic and do not make sense for the average user. In fact, system messages are bad for your reputation as a programmer, as they are clear and tangible evidence of your bugs. Naturally, you'll want to avoid these messages by checking for them in your code, before they hit the operating system. Checking for exceptions in your code will surely make it more cumbersome. Mingling error-checking with the normal flow of your code is inevitable when the language does not support exception handling. The following skeleton code checks for two errors: accessing a null object and out of range array element (the code is just for making a point, do not try compiling with jsc):


var newObject = createObject(dataPiece1, dataPiece2, dataPiece3);
if (newObject == null) {
// do something here when the object was not created
...
}
else {
// getElementIndex return an index or -1 for an error
var index = newObject.getElementIndex();
if (index == -1) {
// handle the error case
...
}
else {
// finally, you can do something with index
...
}
}
Reply With Quote
Sponsored Links
Register and sign in to hide this ad block

  #2 (permalink)  
Old 03-31-2007, 10:04 AM
creek23 creek23 is offline
WMG Deputy Sheriff
 
Join Date: Mar 2007
Posts: 290
iTrader: (0)
creek23 is on a distinguished road
Default

ripped: http://www.webreference.com/js/tips/020912.html
(please leave link when posting articles)
Reply With Quote
  #3 (permalink)  
Old 04-02-2007, 09:11 PM
blokey blokey is offline
WMG Resident Alien
 
Join Date: Mar 2007
Posts: 93
iTrader: (0)
blokey is on a distinguished road
Default

The example code is just error handling - nothing to do with exceptions, which are handled with try...catch blocks in JavaScript.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT. The time now is 05:25 AM.



Freelance Web Designers
Work At Home Forum
Ad Marketplace
Online Deals and Bargains
iPowerWeb Hosting Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0