Search code examples
springsybasemybatisraiserror

How to capture Sybase RAISERROR in Mybatis-Spring?


I am trying to capture error messages in my Java code from stored procedures in Sybase using RAISERROR, but nothing is being caught, even though when I call the proc directly I can see the error is thrown.

I understand that Mybatis-Spring

translates MyBatis exceptions into Spring DataAccessException

So I have coded my Mapper class thusly:

void insertData(Data toInsert) throws Exception, DataAccessException;

I'm trying to catch both of these exceptions, but nothing is caught.

Does anyone have any ideas?

Thanks, Stephen


Solution

  • I found out how to do it:

    try {
        myMapper.insertData(data);
    }
    catch (org.springframework.jdbc.UncategorizedSQLException e) {
        Throwable ee = use.getCause();
        // getMessage on chained exception gets message from RAISERROR
        log.error(ee.getMessage(), e);
    }
    

    Cheers, Stephen