-
-
Save luan03/2e52176452428066d767cb3d4cc29b52 to your computer and use it in GitHub Desktop.
try & catch example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Não sabemos o que tem dentro de "e" pode ser uma adição, | |
remoção ou ambos. O snippet abaixo funciona em todos os casos. | |
*/ | |
Estado.atualizaEstado = function(e){ | |
//Try to add a state; | |
try{ | |
if(typeof(e.added.id) !== undefined){ | |
Estado.selected.push(e.added.id); | |
console.log('Estado added to list'); | |
} | |
}catch(e){ | |
console.log('This wasn\'t an addition'); | |
} | |
//Try to remove a state; | |
try{ | |
if(typeof(e.removed.id) !== undefined){ | |
var index = Estado.selected.indexOf(e.removed.id); | |
Estado.selected.splice(index, 1); | |
console.log('Estado removed from list'); | |
} | |
}catch(e){ | |
console.log('This wasn\'t a remotion'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment