Skip to content

Commit 06a2699

Browse files
authored
minimal: Simplify syntheticException creation
Whether the error is thrown or not does not matter because stacktraces are generated when `new Error()` is called. In other words: the try-catch in `captureException()` and `captureMessage()` is unnecessary, and we can assign the new `Error` instance directly.
1 parent a1e97ea commit 06a2699

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+
let 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+
let 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)