Question

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

Was it helpful?

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top