Skip to content

Commit 9883ba7

Browse files
committed
throw exceptions to prevent sketches from continuing
1 parent 723eb81 commit 9883ba7

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

java/src/processing/mode/java/preproc/PdePreprocessor.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ static private StringList breakCommas(String contents) {
252252
* @param fussy true if it should show an error message if bad size()
253253
* @return null if there was an error, otherwise an array (might contain some/all nulls)
254254
*/
255-
static public SizeInfo parseSketchSize(String code, boolean fussy) {
255+
static public SizeInfo parseSketchSize(String code,
256+
boolean fussy) throws SketchException {
256257
// This matches against any uses of the size() function, whether numbers
257258
// or variables or whatever. This way, no warning is shown if size() isn't
258259
// actually used in the applet, which is the case especially for anyone
@@ -299,8 +300,8 @@ make sure that it uses numbers (or displayWidth/Height), copy into settings
299300
}
300301
}
301302
if (closeBrace == -1) {
302-
// throw new SketchException("Found a { that's missing a matching }");
303-
return null;
303+
throw new SketchException("Found a { that's missing a matching }", false);
304+
// return null;
304305
}
305306
searchArea = sb.toString();
306307
}
@@ -323,19 +324,20 @@ make sure that it uses numbers (or displayWidth/Height), copy into settings
323324
// making a square sketch window? Not going to
324325

325326
if (info.hasOldSyntax()) {
326-
return null;
327+
// return null;
328+
throw new SketchException("Please update your code to continue.", false);
327329
}
328330

329331
if (info.hasBadSize() && fussy) {
330332
// found a reference to size, but it didn't seem to contain numbers
331333
final String message =
332-
"The size of this applet could not automatically\n" +
333-
"be determined from your code. Use only numeric\n" +
334-
"values (not variables) for the size() command.\n" +
335-
"See the size() reference for an explanation.";
334+
"The size of this sketch could not be determined from your code.\n" +
335+
"Use only numbers (not variables) for the size() command.\n" +
336+
"Read the size() reference for more details.";
336337
Base.showWarning("Could not find sketch size", message, null);
337338
// new Exception().printStackTrace(System.out);
338-
return null;
339+
// return null;
340+
throw new SketchException("Please fix the size() line to continue.", false);
339341
}
340342

341343
info.checkEmpty();

0 commit comments

Comments
 (0)