Path: blob/trunk/third_party/closure/goog/debug/error.js
3991 views
/**1* @license2* Copyright The Closure Library Authors.3* SPDX-License-Identifier: Apache-2.04*/56/**7* @fileoverview Provides a base class for custom Error objects such that the8* stack is correctly maintained.9*10* You should never need to throw DebugError(msg) directly, Error(msg) is11* sufficient.12*/1314goog.module('goog.debug.Error');15goog.module.declareLegacyNamespace();1617const utils = goog.require('goog.utils');18192021/**22* Base class for custom error objects.23* @param {*=} msg The message associated with the error.24* @param {{25* message: (?|undefined),26* name: (?|undefined),27* lineNumber: (?|undefined),28* fileName: (?|undefined),29* stack: (?|undefined),30* cause: (?|undefined),31* }=} cause The original error object to chain with.32* @constructor33* @extends {Error}34*/35function DebugError(msg = undefined, cause = undefined) {36// Attempt to ensure there is a stack trace.37if (Error.captureStackTrace) {38Error.captureStackTrace(this, DebugError);39} else {40const stack = new Error().stack;41if (stack) {42/** @override @type {string} */43this.stack = stack;44}45}4647if (msg) {48/** @override @type {string} */49this.message = String(msg);50}5152if (cause !== undefined) {53/** @type {?} */54this.cause = cause;55}5657/**58* Whether to report this error to the server. Setting this to false will59* cause the error reporter to not report the error back to the server,60* which can be useful if the client knows that the error has already been61* logged on the server.62* @type {boolean}63*/64this.reportErrorToServer = true;65}66utils.inherits(DebugError, Error);676869/** @override @type {string} */70DebugError.prototype.name = 'CustomError';717273exports = DebugError;747576