yudaocode/SpringBoot-Labs · error · RuntimeException
直接抛出异常
Error message
直接抛出异常
What it means
Demo endpoint GET /exception in the Sentry + Logback lab that throws RuntimeException('直接抛出异常'). Its purpose is to verify that Sentry's logging integration (sentry-logback appender) captures unhandled exceptions: the uncaught exception reaching the servlet container is reported to Sentry as an event, and it also appears in the logback-configured log destination.
Source
Thrown at lab-51/lab-51-sentry-logback/src/main/java/cn/iocoder/springboot/lab51/sentrydemo/controller/DemoController.java:24
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/demo")
public class DemoController {
private Logger logger = LoggerFactory.getLogger(getClass());
@GetMapping("/sentry")
public String sentry() {
logger.error("[main][我就是展示下异常!]");
return "success";
}
@GetMapping("/exception")
public String exception() {
throw new RuntimeException("直接抛出异常");
}
}
View on GitHub (pinned to 6c12efaed0)
Solutions
- Verify sentry.dsn (and optionally tracesSampleRate) is set before hitting /exception; then check the Sentry dashboard Issues for the '直接抛出异常' event.
- Confirm logback.xml includes io.sentry.logback.SentryAppender if you want exceptions routed through the logging pipeline.
- If no event arrives, enable Sentry debug logging (logging.level.io.sentry=DEBUG) to see transport failures.
- Remove such endpoints in production builds (profile-gate them).
Example fix
// before: raw runtime exception demo
@GetMapping("/exception")
public String exception() {
throw new RuntimeException("直接抛出异常");
}
// after: capture explicitly if you want control over the event
@GetMapping("/exception")
public String exception() {
try {
throw new RuntimeException("直接抛出异常");
} catch (RuntimeException ex) {
logger.error("captured", ex); // SentryAppender picks this up
return "captured";
}
} Defensive patterns
Strategy: try-catch
Validate before calling
// No request validation applies; verify observability config instead:
// assert DSN configured before running the demo
// assertThat(env.getProperty("sentry.dsn")).isNotBlank(); Try / catch
@GetMapping("/exception")
public String exception() {
try {
throw new RuntimeException("直接抛出异常");
} catch (RuntimeException ex) {
logger.error("handled", ex); // SentryAppender reports it
return "captured";
}
} Prevention
- Set sentry.dsn per environment and verify with a debug event before shipping.
- Register SentryAppender in logback.xml for log-based capture.
- Profile-gate demo exception endpoints.
When it happens
Trigger: GET /exception on the lab-51-sentry-logback app; requires Sentry DSN configured (sentry.dsn in application.yaml) and network access to the Sentry server, otherwise the event is dropped (only local logs show it).
Common situations: Initial Sentry setup verification. Frequent issues: DSN missing/wrong so nothing arrives in the Sentry dashboard; logback.xml missing the SentryAppender so only the raw stack trace hits stdout; or Sentry events buffered and flushed late, making developers think integration failed.
Related errors
AI-assisted analysis of yudaocode/SpringBoot-Labs@6c12efaed0 (2026-08-14).
Data as JSON: /api/errors/f6a8b34bce9873d4.
Report an issue: GitHub.