API Database class and exceptions

  • In the Database class, executeQuery() may throw an exception, while execute() and executeUpdate() do not.


    Actually, any of the three can 'go wrong'' but, for the latter two methods, exceptions are caught somewhere before returning (and show up in the log). This means that the caller cannot know if something did go wrong or not.


    Is this by design? Is there any compelling reason to hide the outcome from the caller?

  • Well, on the one hand, we removed the sql exception in order to bring these methods in line with the execute() and executeUpdate() methods of the WorldDatabase: since all commits to the world database are enqueued (for reasons of thread-safety), it's not possible to throw any sql exceptions when calling these methods (even if a error occurred, it always happens with a delay of at least 1 tick).


    On the other hand, we don't want to force people to catch exceptions unless it's necessary. For the executeQuery() method, we kept the sql exception, since the user expects a result anyway, and since this method can be used in combination with a try-with-resources (to auto-close the result set).


    If desired, we can change this behaviour of course ;)

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!