///////////////////// Exception testing - catch ///////////////////////////
var didtry=false;

function didcatch(dothrow) {
	var caught=false;
	try {
		didtry=true;
		if (dothrow) throw new Object;
	}
	catch (e) {
		caught=true;
	}
	return caught;
}

function defectCatch() {
	didtry=false;
	if (didcatch(false)) {
		if (!didtry) return "didn't even try once";
		return "caught when none thrown";
	}
	didtry=false;
	if (!didcatch(true)) {
		if (!didtry) return "didn't try second time";
		return "none caught when thrown";
	}
	return "AOK";
}

///////////////////// Exception testing - finally ///////////////////////////
var finallied,broke,threw;

function finreturn(doreturn) {
	finallied=false;
	try {
		if (doreturn) return;
	}
	finally {
		finallied=true;
	}
}

function finbreak(dobreak) {
	finallied=false;
	broke=false;
	switch (0) {
	case 0:
		try {
			broke=true;
			if (dobreak) break;
			broke=false;
		}
		finally {
			finallied=true;
		}
	}
}

function finthrow(dothrow) {
	finallied=false;
	try {
		didtry=true;
		threw=true;
		if (dothrow) throw new Object;
		threw=false;
	}
	finally {
		finallied=true;
	}
}

function defectFinally() {
	finreturn(false);
	if (!finallied) return "non return skip";
	finreturn(true);
	if (!finallied) return "return skipped";
	
	finbreak(false);
	if (broke)      return "break unexpected";
	if (!finallied) return "non break skip";
	finbreak(true);
	if (!broke)     return "break didn't work";
	if (!finallied) return "break skipped";
	

	var ocaught=false;
	didtry=false;
	try {
		finthrow(false);
	}
	catch (o) {
		ocaught=true;
	}
	if (!didtry)    return "didn't even get to try before non throw";
	if (threw)      return "unexpected throw";
	if (!finallied) return "non throw skip";
	if (ocaught)    return "outer caught non throw";

	ocaught=false;
	didtry=false;
	try {
		finthrow(true);
	}
	catch (o) {
		ocaught=true;
	}
	if (!didtry)    return "didn't even get to try before throw";
	if (!threw)     return "never threw";
	if (!finallied) return "throw skipped";
	if (!ocaught)   return "throw not outer-caught";
	return "AOK";
}