roller-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Markus Fuchs <Markus.Fu...@Sun.COM>
Subject Re: Wrapping persistence strategy exceptions into RollerExceptions
Date Tue, 10 Oct 2006 21:22:50 GMT
Hi Mitesh,

In case of the JPA layer, we should just wrap PersistenceExceptions. 
Declaring a method to throw checked RollerExceptions does not mean that 
RuntimeExceptions can't occur. It's up to the user to handle 
RuntimeExceptions, or not.

Thanks,

-- markus.

Mitesh Meswani wrote:

> Hi Markus,
>
> I think it should be enough to make sure that persistence related 
> exceptions are caught and rethrown as RollerException as you have 
> shown in your example below.
>
> Do you think catching all RuntimeExcpetion, like SQLExceptions or 
> NullPointerExceptions (which most probably should be due to bugs in 
> the persistence provider's code) and rethrowing them as (checked) 
> RollerExceotion would add any value?
>
> Thanks,
> Mitesh
>
> Markus Fuchs wrote:
>
>> Thank you!
>>
>> Mitesh, Craig,
>>
>> Shall catch all RuntimeExceptions then and re-throw them as 
>> RollerExceptions?
>>
>> -- markus.
>>
>> Allen Gilliland wrote:
>>
>>> Markus,
>>>
>>> I don't think there is really a perfect answer to your question, but 
>>> I think that in general any exceptions that are specific to the 
>>> persistence implementation should be caught and rethrown as a 
>>> RollerException.  Whether or not to catch RuntimeExceptions could 
>>> probably be debated, but I think in general it's preferable to catch 
>>> them and rethrow as a normal RollerException.
>>>
>>> -- Allen
>>>
>>>
>>> Markus Fuchs wrote:
>>>
>>>> Hi all,
>>>>
>>>> I'm helping Mitesh implementing the persistence layer abstraction
>>>> for roller.
>>>>
>>>> I'm wondering, if strategy specific exceptions should be wrapped into
>>>> RollerExceptions by the strategy implementation. All persistence
>>>> layers throw RuntimeExceptions: PersistenceExceptions for JPA,
>>>> JDOExceptions for JDO or HibernateExceptions for Hibernate.
>>>>
>>>> Should strategy specific RuntimeExceptions be wrapped into checked
>>>> RollerExceptions? E.g. in JPAPersistenceStrategy, we could implement
>>>> something like:
>>>>
>>>>   public void flush() throws RollerException {
>>>>       try {
>>>>           EntityManager em = getEntityManager(false);
>>>>           if (isTransactionActive(em)) {
>>>>               em.getTransaction().commit();
>>>>           }
>>>>           em.close();
>>>>       } catch (PersistenceException e) {
>>>>           throw new RollerException(e);
>>>>       }
>>>>   }
>>>>
>>>> Also, should be same be done for other persistence layer related 
>>>> exceptions?
>>>> E.g. SQLExceptions or NullPointerExceptions?
>>>>
>>>> Thanks,
>>>>
>>>> -- markus.
>>>
>>>

Mime
View raw message