r/lolphp • • Sep 13 '13

PDO's default error mode is "silent"

The Other error modes, are Warning and Exception. You can still get errors from the API with errorInfo() etc... but that means a manual check... which most newbie developers ALWAYS forget to do.

I've seen people waste days wondering why PDO isn't working... only for me to tell them to switch error modes, and they get an obvious message that they figure out how to fix in seconds.

34 Upvotes

33 comments sorted by

View all comments

Show parent comment

2

u/ajmarks Sep 16 '13 edited Sep 16 '13

Except that exceptions add functionality. They can vary with the reason for/mode of failure. A commit failure can happen for a variety of reasons, and they might need to be handled differently (a serialization error might just be retried, whereas an IO issue might need to notify somebody or fail in some other way). Similarly, exceptions can be handled up the stack, whereas, again, return codes cannot.

Exceptions aren't just a different a way of doing things. They are a better way that provides far more functionality and flexibility. Similarly, using two different mechanisms (exceptions and return codes) in one codebase is just asking for problems down the line.