I like to use present tense when the error/exception-generating code is the "root cause" of the problem, and past tense when I'm merely repackaging an error/exception from a lower layer of code.
For example, when our frontend makes a request to our backend, the backend may return an error message "Cannot connect to database", and the frontend will throw "Failed to retrieve your widgets because: Cannot connect to database".
In general, the only "best practices" in regards to exception/error wording are to make it as clear, unambiguous, non-misleading and consistent as possible. In my opinion the tense convention I just described fits those criteria the best, but there are probably other equally valid conventions.
Read full article from coding style - Exception messages and event logging - which tense to use? - Software Engineering Stack Exchange
No comments:
Post a Comment