Skip to content

Instantly share code, notes, and snippets.

@hail2u
Created May 6, 2009 14:56
Show Gist options
  • Save hail2u/107547 to your computer and use it in GitHub Desktop.
Save hail2u/107547 to your computer and use it in GitHub Desktop.
function formatNameAndEmail(name, email) {
if (typeof name !== "string" || typeof email !== "string") {
throw "InputIsNotString";
} else if (formatNameAndEmail.arguments.length > 2) {
throw "ArgumentsTooLong";
} else {
return name + " <" + email + ">";
}
}
try {
var s = formatNameAndEmail("John Doe", "[email protected]", "Jane Doe", "[email protected]");
} catch (e if e === "InputIsNotString") {
console.log("Input is not string.");
} catch (e if e === "ArgumentsTooLong") {
console.log("Argument is too long.");
} catch (e) {
console.log("Unknown error:" + e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment