|
From: <php...@li...> - 2009-09-24 13:20:56
|
Jost Bekemeier wrote: > I think you'll have to bite the bullet and always throw checked > exceptions in all published API methods of your library. After that > your library will work well when used in Java containers such as EJB > or the PHP/Java Bridge. Ok, I'll look into that as well. My main issue with this is that almost all of what I'm going to be dealing with are Java beans that are persisted via Hibernate. I'm going to be reading and setting properties mainly. The problem is that Hibernate backs the properties with persistent collections that throw several unchecked exceptions. Adding checked exception declarations to all of these getters and setters is going to have a horrible ripple effect in our existing code. It may be that what I am intending to do just isn't workable. Let me make sure I understand the danger of using the unchecked exceptions. I've seen you say that if an unchecked exception is thrown the behavior is undefined. Meaning that in some cases it might work "as expected", and the exception will be thrown on the PHP side. But in other cases the method that threw the exception will return it instead of throwing it, and the code will continue to execute. Is this correct? If so, this may not be a problem for me anyway. I am not attempting to catch unchecked exceptions in order to control the flow of the application. In all cases, if an unchecked exception is thrown, I merely want to log it and display an error message to the end user. Since I'm mainly navigating object graphs and chaining method calls, my code will still fail quickly after an unchecked exception is thrown and ignored. I will end up trying to call a method on what was returned and the method will not exist, and the execution will stop anyway. It seems to me that the worst case scenario will be that the exception or error on the PHP side will not be useful in determining what went wrong. In that case I could determine the source of the problem via the log on the Java side. Are my assumptions correct? Jost Bekemeier wrote: >> Would you mind explaining why? > > If you call a procedure or method that doesn't throw- or is declared > to not throw an exception, the procedure/method will be compiled to > make its call less expensive. Ok, thanks for the explanation. Michael |