refactor: update exception handling to use specific exception types#1843
Merged
zeitlinger merged 1 commit intomainfrom Feb 3, 2026
Merged
refactor: update exception handling to use specific exception types#1843zeitlinger merged 1 commit intomainfrom
zeitlinger merged 1 commit intomainfrom
Conversation
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors exception handling throughout the codebase to use more specific exception types instead of catching generic Exception, improving code clarity and making the expected failure modes more explicit.
Changes:
- Narrowed catch blocks from
Exceptionto specific exception types (RuntimeException,IOException,UnsupportedOperationException,ReflectiveOperationException) - Added explicit null check for InputStream in PrometheusInstrumentationScope before use
- Updated exception handling comments to be more descriptive
- Removed
.havingRootCause()assertions in tests to match the simplified exception wrapping behavior
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| JvmNativeMemoryMetrics.java | Changed catch block from Exception to RuntimeException and improved comment to clarify what runtime failures are caught |
| AbstractDropwizardExports.java | Changed catch block from Exception to RuntimeException for metric collection errors |
| CacheMetricsCollector.java | Changed catch block from Exception to UnsupportedOperationException to specifically handle unavailable evictionWeight metric |
| PrometheusInstrumentationScopeTest.java | Removed .havingRootCause() assertions as IllegalStateExceptions now propagate directly without wrapping |
| PrometheusInstrumentationScope.java | Changed catch block to IOException only, added explicit null check for InputStream, and added required imports |
| OtelAutoConfig.java | Changed catch block from Exception to ReflectiveOperationException for reflection operations |
| HttpExchangeAdapter.java | Changed catch block from Exception to IOException for error response writing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jaydeluca
approved these changes
Feb 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.