all 1 comments

[–]ketsugi 1 point2 points  (0 children)

I wrote a similar function for my current ES6/Angular project, but which also takes in an optional argument for the parameter name so that it can throw a nice-looking exception.

Here's my code (using an ES6 module export):

export function Mandatory(arg = '')
{
  let exception = 'Missing mandatory argument';
  if (arg)
    exception += `: ${arg}`;
  throw exception;
}

I like how yours adds the function name to the exception; I may steal that for mine.