Skip to content

Instantly share code, notes, and snippets.

@dlueth
Last active March 27, 2018 15:48
Show Gist options
  • Select an option

  • Save dlueth/f4a49c7caa974de4e3a29f1e9cae7bec to your computer and use it in GitHub Desktop.

Select an option

Save dlueth/f4a49c7caa974de4e3a29f1e9cae7bec to your computer and use it in GitHub Desktop.

Revisions

  1. dlueth revised this gist Mar 27, 2018. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions error.js
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,15 @@ class CustomError extends Error {
    super(...args);

    Object.defineProperty(this, 'name', { value: this.constructor.name });
    // This is for Node only...
    Error.captureStackTrace(this, this.constructor);

    // ... whereas use this for Browser instead
    /*
    if(Error.captureStackTrace) {
    Error.captureStackTrace(this, CustomError);
    }
    */
    }
    }

  2. dlueth revised this gist Jan 2, 2018. No changes.
  3. dlueth revised this gist Jan 2, 2018. No changes.
  4. dlueth created this gist Jul 25, 2017.
    25 changes: 25 additions & 0 deletions error.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    'use strict';

    class CustomError extends Error {
    constructor(...args) {
    super(...args);

    Object.defineProperty(this, 'name', { value: this.constructor.name });
    Error.captureStackTrace(this, this.constructor);
    }
    }

    class ExtendedError extends CustomError {
    constructor(...args) {
    super(...args);
    }
    }

    try {
    throw new ExtendedError('gnarf')
    } catch(err) {
    console.log(err.name);
    console.log(err);
    }

    module.exports = CustomError;