PDA

View Full Version : Forcing a JavaScript to abort


HiMyNameIs
08-30-03, 06:09 PM
Is there any way to force a JavaScript to abort prematurely. Most languages have an abort() or exit() function that will stop the script or application in its tracks, no questions asked.

Is there something similar for JavaScript?

andreasberglind
09-15-03, 06:00 AM
have you tried break(); ?

HiMyNameIs
09-15-03, 11:31 AM
break() exits the current loop, it doesn't abort the entire script

pat@barelyfitz.com
09-18-03, 11:23 AM
Not the most elegant solutions, but you can wrap your script inside a labeled block:

MY_SCRIPT: {

document.write("<p>testing 1");
break MY_SCRIPT;
document.write("<p>testing 2");

} // MY_SCRIPT label

Or you can use try...catch and throw an exception:

try {

document.write("<p>testing 1");
throw("brokeout");
document.write("<p>testing 2");

} catch (err) {
document.write("<p>err = " + err);
}