10 examples of 'error.capturestacktrace' in JavaScript

Every line of 'error.capturestacktrace' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
16function captureStackTrace(err, fn) {
17 if (Error.captureStackTrace) {
18 Error.captureStackTrace(err, fn);
19 }
20}
157function captureStack() {
158 var error = new Error();
159
160 if (error.stack) {
161 return error.stack;
162 }
163
164 try {
165 throw error;
166 } catch (e) {
167 return e.stack;
168 }
169}
170function captureStack(): string {
171 let error = new Error()
172
173 // Firefox, Chrome, Edge all have .stack defined by now, IE has not.
174 if (error.stack) {
175 return error.stack
176 }
177
178 try {
179 throw error
180 } catch (e) {
181 return e.stack
182 }
183}
10export function getStackTrace(error) {
11 try {
12 return getStackArray(error).join('\n');
13 } catch (ex) {
14 const minimalError = (ex && ex.constructor && ex.message) ? ex.constructor.name + ': ' + ex.message : '';
15 warn(`Could not process stack trace (${minimalError || ex}), printing original.`);
16 return error.stack;
17 }
18}
49function getStack() {
50 var orig = Error.prepareStackTrace;
51 Error.prepareStackTrace = function (_, stack) {
52 return stack;
53 };
54 var err = new Error();
55 Error.captureStackTrace(err, arguments.callee);
56 var stack = err.stack;
57 Error.prepareStackTrace = orig;
58 return stack;
59}
19static rethrow(ex){
20 if( errorsEnabled ){
21 throw ex;
22 }else{
23 errorList.push(ex.msg);
24 }
25}
185function FormatStackTrace(error, frames) {
186 var lines = [];
187 try {
188 lines.push(error.toString());
189 } catch (e) {
190 try {
191 lines.push("");
192 } catch (ee) {
193 lines.push("");
194 }
195 }
196 for (var i = 0; i < frames.length; i++) {
197 var frame = frames[i];
198 var line;
199 try {
200 line = FormatSourcePosition(frame);
201 } catch (e) {
202 try {
203 line = "";
204 } catch (ee) {
205 // Any code that reaches this point is seriously nasty!
206 line = "";
207 }
208 }
209 lines.push(" at " + line);
210 }
211 return lines.join("\n");
212}
516function _exceptionStackTrace(err: any): string {
517 try {
518 throw err;
519 }
520 catch (e) {
521 return e.stack;
522 }
523}
384function replaceStack(error, stack) {
385 let message = error.stack.split('\n')[0];
386 error.stack = [message].concat(stack.split('\n').slice(1)).join('\n');
387}
2function setStack(self) {
3 if (Error.captureStackTrace) {
4 Error.captureStackTrace(self, self.constructor);
5 } else {
6 self.stack = new Error().stack;
7 }
8}

Related snippets