Skip to content

Commit f77ee5d

Browse files
committed
don't catch Throwable all over the place, just Exception
1 parent 5747cd3 commit f77ee5d

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/control/TopLevelExceptionHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public Object execute(VirtualFrame frame) {
9292
result = run(frame);
9393
} catch (PException e) {
9494
printExc(e);
95-
} catch (Throwable e) {
95+
} catch (Exception e) {
9696
if (PythonOptions.getOption(context, PythonOptions.WithJavaStacktrace)) {
9797
boolean exitException = e instanceof TruffleException && ((TruffleException) e).isExit();
9898
if (!exitException) {
@@ -184,7 +184,7 @@ private void handleSystemExit(PException e) {
184184
}
185185

186186
@TruffleBoundary
187-
private static void printStackTrace(Throwable e) {
187+
private static void printStackTrace(Exception e) {
188188
e.printStackTrace();
189189
}
190190

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/AssertNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public Object execute(VirtualFrame frame) {
6464
} catch (PException e) {
6565
// Python exceptions just fall through
6666
throw e;
67-
} catch (Throwable e) {
67+
} catch (Exception e) {
6868
// catch any other exception and convert to Python exception
6969
throw assertionFailed(frame);
7070
}
@@ -86,7 +86,7 @@ private PException assertionFailed(VirtualFrame frame) {
8686
} catch (PException e) {
8787
// again, Python exceptions just fall through
8888
throw e;
89-
} catch (Throwable e) {
89+
} catch (Exception e) {
9090
assertionMessage = "internal exception occurred";
9191
}
9292
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/statement/TryExceptNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public Object execute(VirtualFrame frame) {
9292
}
9393

9494
@TruffleBoundary
95-
private PBaseException getBaseException(Throwable t) {
95+
private PBaseException getBaseException(Exception t) {
9696
return factory().createBaseException(getCore().getErrorClass(PythonErrorType.ValueError), t.getMessage(), new Object[0]);
9797
}
9898

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/PythonErrorStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void recover(Parser recognizer, RecognitionException e) {
5555
super.recover(recognizer, e);
5656
}
5757

58-
static int getLine(Throwable e) {
58+
static int getLine(Exception e) {
5959
if (e instanceof RecognitionException) {
6060
return ((RecognitionException) e).getOffendingToken().getLine();
6161
} else {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/PythonInlineTreeTranslator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public PythonInlineTreeTranslator(PythonCore core, String name, ParserRuleContex
6262
}
6363
} catch (PException e) {
6464
throw e;
65-
} catch (Throwable t) {
65+
} catch (Exception t) {
6666
t.printStackTrace();
6767
throw new RuntimeException("Failed in " + this + " with error " + t, t);
6868
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/PythonParserImpl.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ private static ParserRuleContext preParseWithAntlr(PythonCore core, Source sourc
8787
} else {
8888
input = parser.file_input();
8989
}
90-
} catch (Throwable e) {
90+
} catch (Exception e) {
9191
try {
9292
parser.reset();
9393
input = parser.eval_input();
94-
} catch (Throwable e2) {
94+
} catch (Exception e2) {
9595
if (source.isInteractive() && e instanceof PIncompleteSourceException) {
9696
((PIncompleteSourceException) e).setSource(source);
9797
throw e;
@@ -110,11 +110,11 @@ private static ParserRuleContext preParseInlineWithAntlr(PythonCore core, Source
110110
ParserRuleContext input;
111111
try {
112112
input = parser.single_input();
113-
} catch (Throwable e) {
113+
} catch (Exception e) {
114114
try {
115115
parser.reset();
116116
input = parser.eval_input();
117-
} catch (Throwable e2) {
117+
} catch (Exception e2) {
118118
Node location = getLocation(source, PythonErrorStrategy.getLine(e));
119119
throw core.raise(SyntaxError, location, e.getMessage());
120120
}
@@ -155,7 +155,7 @@ public PythonParseResult parseEval(PythonCore core, String expression, String fi
155155
ParserRuleContext input;
156156
try {
157157
input = parser.eval_input();
158-
} catch (Throwable e) {
158+
} catch (Exception e) {
159159
throw handleParserError(core, e);
160160
}
161161
Source source = Source.newBuilder(expression).name(filename).mimeType(PythonLanguage.MIME_TYPE).build();
@@ -170,7 +170,7 @@ public PythonParseResult parseExec(PythonCore core, String expression, String fi
170170
ParserRuleContext input;
171171
try {
172172
input = parser.file_input();
173-
} catch (Throwable e) {
173+
} catch (Exception e) {
174174
throw handleParserError(core, e);
175175
}
176176
Source source = Source.newBuilder(expression).name(filename).mimeType(PythonLanguage.MIME_TYPE).build();
@@ -184,7 +184,7 @@ public PythonParseResult parseSingle(PythonCore core, String expression, String
184184
ParserRuleContext input;
185185
try {
186186
input = parser.single_input();
187-
} catch (Throwable e) {
187+
} catch (Exception e) {
188188
throw handleParserError(core, e);
189189
}
190190
Source source = Source.newBuilder(expression).name(filename).mimeType(PythonLanguage.MIME_TYPE).build();
@@ -198,13 +198,13 @@ public boolean isIdentifier(PythonCore core, String snippet) {
198198
Python3Parser.AtomContext input;
199199
try {
200200
input = parser.atom();
201-
} catch (Throwable e) {
201+
} catch (Exception e) {
202202
return false;
203203
}
204204
return input.NAME() != null;
205205
}
206206

207-
private static PException handleParserError(PythonCore core, Throwable e) {
207+
private static PException handleParserError(PythonCore core, Exception e) {
208208
return core.raise(SyntaxError, e.getMessage());
209209
}
210210

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/PythonTreeTranslator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public PythonTreeTranslator(PythonCore core, String name, ParserRuleContext inpu
6363
}
6464
} catch (PException e) {
6565
throw e;
66-
} catch (Throwable t) {
66+
} catch (Exception t) {
6767
t.printStackTrace();
6868
throw new RuntimeException("Failed in " + this + " with error " + t, t);
6969
}

0 commit comments

Comments
 (0)