yudaocode/SpringBoot-Labs · error · RuntimeException
直接抛出异常
Error message
直接抛出异常
What it means
Same pattern in the Sentry Spring integration lab: GET /exception throws RuntimeException('直接抛出异常'). Here sentry-spring's exception handling (SentryExceptionResolver / SentryWebFilter) intercepts the uncaught exception before the container's error page and reports it to Sentry with full stack trace and request context, demonstrating deeper Spring integration than the pure logback appender.
Source
Thrown at lab-51/lab-51-sentry-spring/src/main/java/cn/iocoder/springboot/lab51/sentrydemo/controller/DemoController.java:33
private SentryClient sentryClient;
@GetMapping("/sentry")
public String sentry() {
// 上传消息到 Sentry 中
sentryClient.sendMessage("示例消息");
// 上传异常到 Sentry 中
sentryClient.sendException(new RuntimeException("测试异常"));
// 上传事件到 Sentry 中
sentryClient.sendEvent(new EventBuilder().withMessage("示例事件").build());
return "success";
}
@GetMapping("/exception")
public String exception() {
throw new RuntimeException("直接抛出异常");
}
}
View on GitHub (pinned to 6c12efaed0)
Solutions
- Check the Sentry dashboard for the event after calling /exception; verify sentry.dsn is set for the active profile.
- If a @ControllerAdvice swallows exceptions, lower the Sentry resolver's order or capture inside the advice with Sentry.captureException(ex).
- Use the /sentry endpoint's manual API (sendException/sendEvent) for events you want to report without failing a request.
- Gate demo endpoints to dev profiles.
Example fix
// before: global advice hides the exception from Sentry
@RestControllerAdvice
class Global {
@ExceptionHandler(Exception.class)
CommonResult<?> handle(Exception ex) { return CommonResult.error(); }
}
// after: forward to Sentry inside the advice
@RestControllerAdvice
class Global {
@ExceptionHandler(Exception.class)
CommonResult<?> handle(Exception ex) {
Sentry.captureException(ex);
return CommonResult.error();
}
} Defensive patterns
Strategy: try-catch
Try / catch
// If a @ControllerAdvice handles exceptions, forward to Sentry there:
@ExceptionHandler(Exception.class)
CommonResult<?> handle(Exception ex) {
Sentry.captureException(ex);
return CommonResult.error();
} Prevention
- Order Sentry's exception resolver ahead of your own handlers or capture explicitly inside advice.
- Confirm the DSN is set in every profile that should report (not just default).
- Use manual SentryClient.sendException for non-failing events.
When it happens
Trigger: GET /exception on lab-51-sentry-spring. The neighboring /sentry endpoint shows manual reporting via sentryClient.sendException/sendEvent; this one relies on automatic capture. Requires a configured DSN.
Common situations: Verifying automatic exception capture in Spring apps. Common issues: order of the Sentry filter/HandlerExceptionResolver vs custom @ControllerAdvice — a global handler that fully consumes the exception prevents Sentry from seeing it unless Sentry's resolver is ordered first (sentry.resolve-order); or the DSN only set in one profile so capture works in dev but not prod.
Related errors
AI-assisted analysis of yudaocode/SpringBoot-Labs@6c12efaed0 (2026-08-14).
Data as JSON: /api/errors/68b903fbbf4a85d9.
Report an issue: GitHub.