DEV Community


Posted on

Throw error on missing arguments

In one of his posts Krasimir Tsonev showed a nice tips to "force" passing arguments to a javascript function.

Here is an example :


const {html, render} = mvu;

function MissinArgException (message) {
  this.message = message;

function Error(msg) {
  throw new MissinArgException(msg);

function greet (
    connected = Error("connected missing")
    return html`
            && html`<h2>Hello ${user}</h2>` 
            || html`<h2>${user} is not logged</h2>`

try {
  render(greet("Marcel", true), document.body)
catch (error) {
  alert (error.message)
Enter fullscreen mode Exit fullscreen mode

You can try if here ArgMissing

Remove the 'connected' argument and see what happens...

Top comments (0)