Skip to content

Commit 008982f

Browse files
authored
ref(minimal): Simplify syntheticException creation (#4691)
In the olden days of raven-js, we had to actually _throw_ an error in order to guarantee it'd have a stack. Since that's no longer the case in modern browsers, we can simply create the error, with no need for a `try-catch`.
1 parent 4e65cb7 commit 008982f

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

packages/minimal/src/index.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,8 @@ function callOnHub<T>(method: string, ...args: any[]): T {
3636
*/
3737
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
3838
export function captureException(exception: any, captureContext?: CaptureContext): string {
39-
let syntheticException: Error;
40-
try {
41-
throw new Error('Sentry syntheticException');
42-
} catch (exception) {
43-
syntheticException = exception as Error;
44-
}
39+
const syntheticException = new Error('Sentry syntheticException');
40+
4541
return callOnHub('captureException', exception, {
4642
captureContext,
4743
originalException: exception,
@@ -57,12 +53,7 @@ export function captureException(exception: any, captureContext?: CaptureContext
5753
* @returns The generated eventId.
5854
*/
5955
export function captureMessage(message: string, captureContext?: CaptureContext | Severity): string {
60-
let syntheticException: Error;
61-
try {
62-
throw new Error(message);
63-
} catch (exception) {
64-
syntheticException = exception as Error;
65-
}
56+
const syntheticException = new Error(message);
6657

6758
// This is necessary to provide explicit scopes upgrade, without changing the original
6859
// arity of the `captureMessage(message, level)` method.

0 commit comments

Comments
 (0)