3 ms·
I wonder whether it would be a bad idea to have a "dev" mode where exceptions are thrown and a "production" mode of compilation where every single statement is
by dheera 6y ago
I wonder whether it would be a bad idea to have a "dev" mode where exceptions are thrown and a "production" mode of compilation where every single statement is wrapped in a try-catch block with a default behavior. For example:
histogram = getHistogram();
should be wrapped automatically in:
try { histogram = getHistogram(); }
catch(Exception e) { console.log(e.toString()); histogram = DEFAULT_HISTOGRAM; }
Something like:
y = a / b;
should be wrapped in:
try { y = a/b; }
catch(Exception e) { console.log(e.toString()); y = 1e999; }
Wrap every function call like this, and just don't let Java exceptions bring down an entire system in production especially when a lot of the time it's just a petty UI issue.
Obviously never do it in development though. But odd UI behavior instead of crashes might make a bunch more users happy which is ultimately what matters.
- nicoburns 6y agoIt seems that all you'd need is a single try-catch around the high-level operation. I inherited a system where all the errors were swallowed and it was a nightmare. If something failed it was impossible to tell why.
- dheera 6y agoYeah, I agree that the developer shouldn't do that in the source code. I'm more thinking of a compilation mode where the system tries to consistently do something just slightly smarter than give up when there is an exception, and that is strictly only for production use. A divide by zero error on a button's width shouldn't cause a spacecraft to give up and abort its mission to the moon. That wouldn't happen, but it's just a figurative description of what I would like. It's ridiculous for an OS to go into a boot loop because of a color histogram. A better behavior would be for the background to be set to an array of NaNs, and the background renderer to fail gracefully to a plain black or white background.
- londons_explore 6y agoFloating point NaN is pretty close to what you're describing for floats only. Really we need some kind of NaN value for all java objects.
- 0x0 6y agoAh, but your catch block doesn't look for exceptions in console, log, or toString().