Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Designing error codes [closed]

Tags:

error-code

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) :

  • error codes 51xx => Informational
  • error codes 52xx => success
    • error codes [5200-5220) => success on verification
    • error codes [5220-5240) => success on sent data
    • error codes [5240-5260) => success on creation
    • error codes [5260-5280) => success on modification
    • error codes [5280-5300) => misc.
  • error codes 53xx => To inform that some action needs to be taken
  • error codes 54xx => client related error codes
  • error codes 5500-5549 => server related error code with problem in service layer
  • error codes 5550-5600 => server related error codes with problem in database layer
like image 922
r15habh Avatar asked Apr 28 '11 17:04

r15habh


People also ask

How do you define error code?

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.

What is one way in which exceptions are superior to error codes?

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.


2 Answers

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.

like image 150
drowe Avatar answered Oct 05 '22 11:10

drowe


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.

like image 29
Nik Avatar answered Oct 05 '22 12:10

Nik