{"record":{"id":"f6a8b34bce9873d4","repo":"yudaocode/SpringBoot-Labs","slug":"error-f6a8b3","errorCode":null,"errorMessage":"直接抛出异常","messagePattern":"直接抛出异常","errorType":"http","errorClass":"RuntimeException","httpStatus":500,"severity":"error","filePath":"lab-51/lab-51-sentry-logback/src/main/java/cn/iocoder/springboot/lab51/sentrydemo/controller/DemoController.java","lineNumber":24,"sourceCode":"import org.springframework.web.bind.annotation.RequestMapping;\nimport org.springframework.web.bind.annotation.RestController;\n\n@RestController\n@RequestMapping(\"/demo\")\npublic class DemoController {\n\n    private Logger logger = LoggerFactory.getLogger(getClass());\n\n    @GetMapping(\"/sentry\")\n    public String sentry() {\n        logger.error(\"[main][我就是展示下异常！]\");\n\n        return \"success\";\n    }\n\n    @GetMapping(\"/exception\")\n    public String exception() {\n        throw new RuntimeException(\"直接抛出异常\");\n    }\n\n}\n","sourceCodeStart":6,"sourceCodeEnd":28,"githubUrl":"https://github.com/yudaocode/SpringBoot-Labs/blob/6c12efaed06d12907a0f40dd2ad1f7020aec8798/lab-51/lab-51-sentry-logback/src/main/java/cn/iocoder/springboot/lab51/sentrydemo/controller/DemoController.java#L6-L28","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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)."],"exampleFix":"// before: raw runtime exception demo\n@GetMapping(\"/exception\")\npublic String exception() {\n    throw new RuntimeException(\"直接抛出异常\");\n}\n\n// after: capture explicitly if you want control over the event\n@GetMapping(\"/exception\")\npublic String exception() {\n    try {\n        throw new RuntimeException(\"直接抛出异常\");\n    } catch (RuntimeException ex) {\n        logger.error(\"captured\", ex); // SentryAppender picks this up\n        return \"captured\";\n    }\n}","handlingStrategy":"try-catch","validationCode":"// No request validation applies; verify observability config instead:\n// assert DSN configured before running the demo\n// assertThat(env.getProperty(\"sentry.dsn\")).isNotBlank();","typeGuard":null,"tryCatchPattern":"@GetMapping(\"/exception\")\npublic String exception() {\n    try {\n        throw new RuntimeException(\"直接抛出异常\");\n    } catch (RuntimeException ex) {\n        logger.error(\"handled\", ex); // SentryAppender reports it\n        return \"captured\";\n    }\n}","preventionTips":["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."],"tags":["sentry","logback","error-tracking","tutorial","deliberate-throw"],"backgroundTag":null,"analyzedSha":"6c12efaed06d12907a0f40dd2ad1f7020aec8798","analyzedAt":"2026-08-14T13:06:31.500Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}