Skip to content

Change catch Throwable to Exception#1690

Open
wmdietl wants to merge 2 commits intomasterfrom
catch-throwable
Open

Change catch Throwable to Exception#1690
wmdietl wants to merge 2 commits intomasterfrom
catch-throwable

Conversation

@wmdietl
Copy link
Copy Markdown
Member

@wmdietl wmdietl commented May 2, 2026

I reviewed all catch (Throwable occurrences and for these it seemed better to catch Exception.
Catching Throwable also catches Errors -- OutOfMemoryError, StackOverflowError, LinkageError, AssertionError, ThreadDeath. Wrapping these seems confusing.
Note how SourceChecker already wraps Throwables and outputs a message.

Copilot AI review requested due to automatic review settings May 2, 2026 21:39
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates exception handling across the framework to avoid catching Throwable (and therefore Errors), limiting wrapping/reporting to Exception cases.

Changes:

  • Replaced multiple catch (Throwable …) blocks with catch (Exception …) in type/flow/stub components.
  • Kept existing error-reporting/wrapping behavior but restricted it to exceptions (e.g., BugInCF.addLocation, warnings).
  • Adjusted local variable names accordingly (te, etc.).

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
framework/src/main/java/org/checkerframework/framework/type/TypeFromTree.java Catch Exception instead of Throwable when wrapping with BugInCF.addLocation.
framework/src/main/java/org/checkerframework/framework/type/DefaultTypeHierarchy.java Catch Exception instead of Throwable in bounds containment workaround path.
framework/src/main/java/org/checkerframework/framework/type/AnnotatedTypeFactory.java Catch Exception instead of Throwable while parsing ajava files.
framework/src/main/java/org/checkerframework/framework/stub/ToIndexFileConverter.java Main method now catches Exception instead of Throwable before exiting.
framework/src/main/java/org/checkerframework/framework/stub/AnnotationFileParser.java Parser helper methods now catch Exception instead of Throwable and warn.
framework/src/main/java/org/checkerframework/framework/flow/CFAbstractTransfer.java Catch Exception instead of Throwable when wrapping with BugInCF.addLocation.
framework/src/main/java/org/checkerframework/framework/flow/CFAbstractAnalysis.java Catch Exception instead of Throwable when wrapping in BugInCF.
framework/src/main/java/org/checkerframework/common/basetype/BaseTypeVisitor.java Catch Exception instead of Throwable when constructing the type factory and wrapping in BugInCF.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

} catch (Exception ex) {
// Work around:
// https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8265255
if (ex.getMessage().contains("AsSuperVisitor")) {
currentFileAjavaTypes.parseAjavaFileWithTree(ajavaPath, root);
} catch (Throwable e) {
} catch (Exception e) {
throw new Error(
} catch (Throwable e) {
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants