Am I allowed to throw an error inside a ternary operator? Is this valid:
function foo(params) {
var msg = (params.msg) ? params.msg : (throw "error");
// do stuff if everything inside `params` is defined
}
What I'm trying to do is make sure all of the parameters needed, which are in a param
object, are defined and throw an error if any one is not defined.
If this is just foolish, is there a better approach to doing this?
question from:https://stackoverflow.com/questions/9370606/javascript-error-handling-can-i-throw-an-error-inside-a-ternary-operator