RE: Exceptions (was: RE: [Avalon4:PROPOSAL] Context Consensus)
"Berin Loritsch" <[email protected]>
| Newsgroups | gmane.comp.jakarta.avalon.apps.devel |
|---|---|
| Message-ID | <000901c2a160$9416cdd0$2100a8c0__8695.95399494774$1039643961@acsdom1.citius.com> |
> From: Noel J. Bergman [mailto:[email protected]] > > Leo wrote: > > True, but here we're really going into whether RuntimeExceptions > > should be tested for and caught. > > Personally, I have an extremely dim view of the lazy use of > RuntimeException > instead of properly declaring exceptions in the interface. > Debugging them > in client code is a PITA as it is, and in this case because > we are dealing > with a dynamic assembly model, the an end user deployment may > be calling a > component that the developer has never seen. Its a PITA any way you look at it. > In this case, the Container is passing in a narrow type with > the expectation > that the class will downcast it. Personally, I *would* recommend the > try-catch coding pattern, and doing it immediately in contextualize. Yep, or at the *very least* casting it immediately in contextualize so that the container can catch that problem. > Berin Loritsch wrote: > > A *Container* needs to be able to recover from ALL exceptions > > thrown by components. This is a real practical requirement. If > > a poorly written optional component introduces a > NullPointerException > > or a ClassCastException, and the container does not catch it and > > recover from it then the whole application will fail. > > I agree that container (and all platform code) should be > robust. But here's > a rub. There is no guarantee that the Component won't take > the Context, > squirrel it away, and cast the thing later when it needs it. > And when THAT > happens, who sees the ClastCastException? Quite likely some other > component, whom is not expecting those kinds of internal > errors to leak out. And then the component fails regarding its contracts... Anyway I consider the practice a fragile contract at best.