Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/third_party/closure/goog/debug/error.js
3991 views
1
/**
2
* @license
3
* Copyright The Closure Library Authors.
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
/**
8
* @fileoverview Provides a base class for custom Error objects such that the
9
* stack is correctly maintained.
10
*
11
* You should never need to throw DebugError(msg) directly, Error(msg) is
12
* sufficient.
13
*/
14
15
goog.module('goog.debug.Error');
16
goog.module.declareLegacyNamespace();
17
18
const utils = goog.require('goog.utils');
19
20
21
22
/**
23
* Base class for custom error objects.
24
* @param {*=} msg The message associated with the error.
25
* @param {{
26
* message: (?|undefined),
27
* name: (?|undefined),
28
* lineNumber: (?|undefined),
29
* fileName: (?|undefined),
30
* stack: (?|undefined),
31
* cause: (?|undefined),
32
* }=} cause The original error object to chain with.
33
* @constructor
34
* @extends {Error}
35
*/
36
function DebugError(msg = undefined, cause = undefined) {
37
// Attempt to ensure there is a stack trace.
38
if (Error.captureStackTrace) {
39
Error.captureStackTrace(this, DebugError);
40
} else {
41
const stack = new Error().stack;
42
if (stack) {
43
/** @override @type {string} */
44
this.stack = stack;
45
}
46
}
47
48
if (msg) {
49
/** @override @type {string} */
50
this.message = String(msg);
51
}
52
53
if (cause !== undefined) {
54
/** @type {?} */
55
this.cause = cause;
56
}
57
58
/**
59
* Whether to report this error to the server. Setting this to false will
60
* cause the error reporter to not report the error back to the server,
61
* which can be useful if the client knows that the error has already been
62
* logged on the server.
63
* @type {boolean}
64
*/
65
this.reportErrorToServer = true;
66
}
67
utils.inherits(DebugError, Error);
68
69
70
/** @override @type {string} */
71
DebugError.prototype.name = 'CustomError';
72
73
74
exports = DebugError;
75
76