I'm designing an application which returns JSON string to clients in response, and an error code in case some exception occurs. I'm planning to design a set of error codes which can help me determine what type of error occurred just by looking at the code.
Is there any convention which can be followed for grouping same type of error codes?
EDIT
Thanks for the replies.
Here's how I grouped the error codes (somewhat similar to HTTP status codes) :
An error code is an indicator to a user of a piece of hardware or software that an error has occurred and an identifier regarding the specific error responsible for the problem. This code is typically part of an error message that may be displayed for the user of a computer or similar device.
The biggest benefit exception handling has over error codes is that it changes the flow of execution, which is important for two reasons. When an exception occurs, the application is no longer following it's 'normal' execution path.
Group your errors together in logical units, and determine the convention you want to use. Some people use namespacing, or numbered grouping to make errors easily identifiable, but it largely depends on how many error codes you need to support, and how you want to group them. There isn't a 'standard' convention that I know of.
In my experience, that's really up to you. Error codes, however defined, will always have to be explained by you, so you can assign/group them however you please. Users don't care.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With