Skip to content

Instantly share code, notes, and snippets.

@gchacaltana
Last active January 13, 2018 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gchacaltana/2dde20ae45669f7f102e70a84c7f8d99 to your computer and use it in GitHub Desktop.
Save gchacaltana/2dde20ae45669f7f102e70a84c7f8d99 to your computer and use it in GitHub Desktop.
Ejemplo JS para devolver una excepción.
function printError(message) {
throw new Error(message);
}
function validatePlayers(n) {
if (isNaN(n)) {
var message = "BooGame: Ingresa un valor númerico para la cantidad de jugadores.";
printError(message)
}
return true;
}
function start(n) {
if (validatePlayers(n)) {
console.log("BooGame: Cargando....");
}
}
//Devuelve error
start("dos");
//Forma correcta: start(2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment