Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js throw custom error

class CustomError extends Error {
  constructor(foo = 'bar', ...params) {
    // Pass remaining arguments (including vendor specific ones) to parent constructor
    super(...params)

    // Maintains proper stack trace for where our error was thrown (only available on V8)
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, CustomError)
    }

    this.name = 'CustomError'
    // Custom debugging information
    this.foo = foo
    this.date = new Date()
  }
}

try {
  throw new CustomError('baz', 'bazMessage')
} catch(e) {
  console.error(e.name)    //CustomError
  console.error(e.foo)     //baz
  console.error(e.message) //bazMessage
  console.error(e.stack)   //stacktrace
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: make a get request in node js 
Javascript :: get time from date 
Javascript :: how to get an absolute in js 
Javascript :: how to use ctx on canvas js 
Javascript :: submit form in vue 
Javascript :: json stringify pretty 
Javascript :: moment js - to find if dates are same by day 
Javascript :: check if element has specific child javascript 
Javascript :: p5js cdn 
Javascript :: aos animation angular 
Javascript :: javascript text word wrap replace 
Javascript :: ReferenceError: primordials is not defined 
Javascript :: how to detect a url change 
Javascript :: ref css in jsp 
Javascript :: How to write inside a div using javascript 
Javascript :: javascript string to float 
Javascript :: dynamic select option dropdown in jquery 
Javascript :: get date javascript 
Javascript :: how to change style of an element using javascript 
Javascript :: jquery selector exists 
Javascript :: how to get seconds in timstamps js 
Javascript :: remove array item from localStorage 
Javascript :: how to convert entered number into currency in words in javascript 
Javascript :: This is the RegEx for Roman numerals 
Javascript :: webpack bundle analyzer 
Javascript :: nodejs file exists 
Javascript :: parse csv javascript 
Javascript :: jquery set inner text 
Javascript :: chartjs line color 
Javascript :: package json scripts multiple commands 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =