Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error handling

Status
Not open for further replies.

KeithTrangmar

Programmer
Jan 16, 2004
29
GB
I hope this is the right forum to ask in.

I'm using a JS-based script under the Windows Scripting Host to run a series of processes. One of them has started failing occasionally, and as I don't have any error handling yet built into my script, the whole thing just dies at that point. I want to be able to take some appropriate action & recover gracefully.

In the context of a web page I've just used a function called "onerror" in the past, but this doesn't appear to have any effect in this environment. I'm sure there must be a way of doing it, but half an hour digging through MSDN yielded nothing helpful.

Any suggestions, please?



Keith Trangmar
Harlend Computer Services
Maidstone, Kent. UK.
 

Have you looked into using try-catch?

Code:
var wsh = new ActiveXObject("WScript.Shell");

try {
    wsh.RegRead ( ... some reg key ... );
}

catch ( e ) {

    if ( e != 0 ) {

        WScript.Echo ("Error: " + e + " Entry doesn't exists");
        WScript.Quit(1);
    }
}
 
Keith,

This should work in JavaScript:

Code:
try
{
	// do stuff here
}
catch (err)
{
	// do error routine here
}

Hope this helps,

Dan
 
Ah, splendid, thanks chaps, that'll do nicely.



Keith Trangmar
Harlend Computer Services
Maidstone, Kent. UK.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top