I’ve always found C++'s “trend” of handling normal or non-exceptional system errors with exceptions lackluster (and I’m being charitable). Overall trimming things down to (basically) passing around a couple integers and telling the user to check their manual is much better, much less error prone, and much more efficient and deterministic.

  • ulterno
    link
    fedilink
    English
    arrow-up
    6
    ·
    edit-2
    2 months ago

    telling the user to check their manual

    • So I made an API for a DB.
    • The client was full on using Qt Framework with Qt Creator, so I also made it in Qt.
    • I return QSqlError in my functions and point the user to QSqlError documentation in Qt
      • I even show them that they can press F1 at any time in Qt Creator to get the help page
    • Months later, client engineers raise problem with senior management that they don’t have a bool return value (I am sitting 10m away in the same room as the client. Senior management is in another state)
    • I press F1 on their computer and show the user bool QSqlError::isValid()
      • Note again, that all client devs at this point, have been using Qt, years before I enter.
    • User says they don’t have a bool result.
      • I open their code and show them how to use isValid() in an if statement.
    • User puts a requirement for custom functions returning bool
      • I make more functions for that
    • Months later, I get a bug report, stating that the deleteDocument function is deleting the document but returning false.
    • I check the code
    API::deleteDocument(docId);
    
    if (API::deleteDocument(docId))
    {
      // output to UI
    }
    

    Yes, they called deleteDocument on the same ID twice.

    BTW, I did create a manual with usage examples.

    A few months later, a senior engineer on the client side checks their code and tells me to throw exceptions for everything, because half of the time, the user-devs are not checking the QSqlError return values.


    [[nodiscard]]

    From what I remember, that gives a warning an not an error.
    The clients’ code already has >400 warnings[1] on every build. They won’t care


    1. edit: fixed wrong word ↩︎