Good point. I went back to the drawing board, but without breaking the existing API expectation of calling size() in setup, you cannot stop forward execution of setup() in a safe manner without excepting.
Why did you have to improve Processing's exception handling by catching a more specific exception instead of catching RuntimeException and checking its message as in 0135?
To explain, by happy coincidence, when you implement setup() in JRuby and receive an exception out of a Java call (to size()) that it does not rescue, JRuby wraps the exception with an org.jruby.exceptions.RaiseException, which extends RuntimeException, and rethrows it. In 0135, this worked nicely. In 0148, not so much.
JRuby Java integration ticket for reference:
http://jira.codehaus.org/browse/JRUBY-1300
I think I will have to maintain an alternative patch against Processing for my project until the JRuby Java exception pass-through issue gets resolved. To keep the patch at a minimum, I cheated and introduced the pattern of 0135 back into 0148 as a secondary catch while keeping the RendererChangeException pattern in place. Catching RuntimeException rather than JRuby's exception, though less specific, avoids a compile-time dependency on JRuby:
Index: core/src/processing/core/PApplet.java
===================================================================
--- core/src/processing/core/PApplet.java (revision 4275)
+++ core/src/processing/core/PApplet.java (working copy)
@@ -1378,8 +1378,21 @@
//println("Done with setup()");
} catch (RendererChangeException e) {
+
// Give up, instead set the new renderer and re-attempt setup()
return;
+
+ // Catches on JRuby RaisedException when setup() implemented in JRuby
+ // and size() called with a different renderer until resolution of
+ // http://jira.codehaus.org/browse/JRUBY-1300
+ } catch (RuntimeException e) {
+ String message = e.getMessage();
+ String name = RendererChangeException.class.getName();
+ if (message.matches(name)) {
+
+ // Give up, instead set the new renderer and re-attempt setup()
+ return;
+ }
}
this.defaultSize = false;
I appreciate you considering the original patch proposal. Thanks for your work on Processing.