We'll handle the errors for you - and we're not telling you how

  • I'm trying to use Spring-JDBC for data access, and whilst it's great not to have to deal with connection pools and JBCD drivers, I can't find it documented anywhere what I'll actually get back if an unrecoverable error occurs under the hood of one of their abstractions.

    Specifically, I'm using SimpleJdbcCall to call stored procedures in a database.

    Sample code:

    SimpleJdbcCall call = new SimpleJdbcCall()
        .returningResultSet("results", new MyRowMapper());
    SqlParameterSource inParams = new MapSqlParameterSource()
        .addValue("inputParam", "foo");
    Map<String, Object> returnedData = call.execute(inParams);
    MyClass results = (MyClass) returnedData.get("results");

    What happens if there's an error in the database?

    doesn't throw any checked exceptions. Do I get an empty map? Or null? Or a runtime exception of some sort? Why does it not say this anywhere? Please help me, I need to finish this by last week.

    I'm trying to produce a webservice. Any DB errors are probably unrecoverable (or at least I don't have time to work out how to recover from them and for now it's not a must-have), but I do need to catch them and return a user-friendly error.

  • Impossible Mission Players - A

    I have NFC about anything in Spring-JDBC (Sounds like a Java thing), but their documentation suggests that "All translated exceptions are unchecked, which gives you the option of catching the exceptions from which you can recover while allowing other exceptions to be propagated to the caller".

    Assuming this is written from the point of view of the adapter, that means you're supposed to handle generic exceptions I guess?

    Also see here a SO post I randomly found:

    Snipped, in case proxy blocked:

  • @Tsaukpaetra Thank you! I don't know why I failed to find that. Looks like all DB errors turn up as some subclass of DataAccessException, so I can catch that. I was taught never to catch runtime exceptions but at least that beats catching Exception which I was seriously considering doing.

    You are a lifesaver. Possibly literally, since if I don't get this finished tomorrow I will probably have a complete breakdown and not have to finish it because I'll have been wheeled away by one emergency service or other.

  • @CarrieVS It can't be that important.

  • @blakeyrat said in We'll handle the errors for you - and we're not telling you how:

    It can't be that important.

    No. but I have anxiety issues.

  • @CarrieVS I have the opposite.

Log in to reply

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.