[Seasar-user:1358] Re: S2Dao でエラー処理

Yasuo Higa higa
2005年 4月 6日 (水) 01:08:32 JST


<20041214104133.EHY26727.mps5.plala.or.jp @ rmail.mail.plala.or.jp> の、
   "[Seasar-user:1356] Re: S2Dao でエラー処理" において、
   "suga <suga_k @ rmail.plala.or.jp>"さんは書きました:

ひがです。

> 初めまして、suga と申します。

> On Tue, 14 Dec 2004 18:50:08 +0900 (JST)
> 須賀 祐一 <yu1_suga @ ybb.ne.jp> wrote:
> 
> 
> import org.seasar.framework.aop.interceptors.ThrowsInterceptor;
> 
> public class AlreadyExistsThrowsInterceptor extends ThrowsInterceptor {
>     public void handleThrowable(Throwable t, MethodInvocation invocation) {
>         if (t instanceof SQLRuntimeException) {
>             SQLException e2 = (SQLException) t.getCause();
>             if ("23000".equals(e2.getSQLState())) {
>                 if (e2.getErrorCode() == -104) {
>                     throw new AlreadyExistsRuntimeException(e2);
>                 }
>             }
>         }
>         throw t;
>     }
> }
> 
public void handleThrowable(SQLRuntimeException t, MethodInvocation invocation) {
    SQLException e2 = (SQLException) t.getCause();
    if ("23000".equals(e2.getSQLState())) {
        if (e2.getErrorCode() == -104) {
            throw new AlreadyExistsRuntimeException(e2);
        }
    }
}
でもっと簡単にいけます。
処理したい例外の数分、handleThrowableを書いて、最初の引数を処理したい例外の
型にします。
---
Yasuo Higa <higa @ isid.co.jp>
INFORMATION SERVICES INTERNATIONAL-DENTSU,LTD.



Seasar-user メーリングリストの案内