Throw Errors vs Return Errors

Benchmark created on


Setup

function throwError(value) {
	if (!value) {
		throw new Error("No value");
	}
}

function returnError(value) {
	if (!value) {
		return new Error("No value");
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
Throw Error (with try-catch)
try {
	throwError();
} catch (e) {}
ready
Return Error
const value = returnError();
if (value instanceof Error) {}
ready
Throw Error (no error)
throwError(true);
ready
Return Error (no error)
returnError(true);
ready
Throw Error (no error but with try-catch)
try {
	throwError(true);
} catch (e) {}
ready
Return Error (no error but with error checks)
const value = returnError(true);
if (value instanceof Error) {}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.