Best way to define error codes/strings in Java?

前端 未结 13 780
别那么骄傲
别那么骄傲 2020-12-12 08:37

I am writing a web service in Java, and I am trying to figure out the best way to define error codes and their associated error strings. I need to have a nu

13条回答
  •  遥遥无期
    2020-12-12 09:25

    I (and the rest of our team in my company) prefer to raise exceptions instead of returning error codes. Error codes have to be checked everywhere, passed around, and tend to make the code unreadable when the amount of code becomes bigger.

    The error class would then define the message.

    PS: and actually also care for internationalization !
    PPS: you could also redefine the raise-method and add logging, filtering etc. if required (at leastin environments, where the Exception classes and friends are extendable/changeable)

提交回复
热议问题