Hi Noel, Yes, I tend to do that as well so I'm +1 for this approach. :)
Throwing a RuntimeException is preferable to doing nothing because if those 'should never happen' exceptions do occur for whatever bizarre reason and we just swallow them we risk putting the client in to an 'unknown state'. For instance, I could easily imagine the code in your first example quickly resulting in a NullPointerException further along in the execution and that would be hard to debug. The RuntimeException removes that ambiguity. I think I mentioned it before, but I still think some kind of 'top level exception handler' would still be useful. People can then plug in custom error reporting mechanisms. Cheers, Chris 2009/8/6 Noel Grandin <[email protected]> > Hi > > I notice that in places Pivot has code like this: > try { > ... stuff.... > } catch(IllegalAccessException exception) { > } catch(InstantiationException exception) { > } > > My preferred pattern for ignored exceptions is this: > try { > ... stuff.... > } catch(IllegalAccessException exception) { > throw new RuntimeException(exception); // should never happen > } catch(InstantiationException exception) { > throw new RuntimeException(exception); // should never happen > } > > Just so that I get a stacktrace in those rare cases, where yes, somebody > did something extra-ordinarily stupid and managed to trigger the exception. > > Comments? > > -- Noel. >
