• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

handle exceptions

Hello there,
I know it is quite simple but I am still unable to make it work.

I want to catch exception in the scriptaculous script I have,

the script calls another functions

createNode('node1');
createNode('node2');
createNode('node3');

if there is no node2 object exist, it should simply ignore the call and not say -- node3 object not found
please advice.
regards
sam
0
niidmore
Asked:
niidmore
  • 3
  • 3
1 Solution
 
ChetOS82Commented:
You can use try/catch blocks around each one.  Or, you could make sure that 'node2' exists before you call the function.

try {
     createNode('node2');
} catch(ex) {

}

Since 'node2' is a string, I don't know how it is actually used.  Assuming it is the ID of a HTML element do:
if (document.getElementById('node2')) {
     createNode('node2');
}
0
 
niidmoreAuthor Commented:
thanks chet, that worked for me. Yes, node2 is an ID of a HTML element in the example above.

http://xxx.xxx.xxx.26/vanillasite/carlton.asp

If you please follow the url above, the actual script works only in IE but not in Firefox. Can you please see if there is something wrong?
thanks for looking.
cheers
sam
0
 
ChetOS82Commented:
Modify the catch block to display the error.  It looks like the last childnode in your createEffect function is throwing the error, which causes the execution to flow the to catch block.  This skips your other two createEffect calls.

try {
...
} catch(ex) {
     alert(ex);
}
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
niidmoreAuthor Commented:
yes you are right ! could you also please let me know the fix.
much appreciate for your help.
regards
sam
0
 
ChetOS82Commented:
No, I am not sure what the problem is exactly.  I suggest that you download Firebug for Firefox and step through the code checking it with the debugger.
0
 
niidmoreAuthor Commented:
ok thanks for your help though
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now