Pages: [1]   Go Down
Author Topic: How about standard Error Codes?  (Read 888 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How about having Arduino IDE ship with an include file with standard error codes that could be used by libraries and sketches:

Code:
#ifndef ERRORCODES_H
#define ERRORCODES_H

//! \version 1.2
enum ErrorCode {
    SUCCESS=        0,
    ERROR_CHECKSUM=         -9999,
    ERROR_TIMEOUT=          -9998,
    ERROR_DISABLED=         -9997,
    ERROR_UNSUPPORTED=      -9996,
    ERROR_UNKNOWN_RSP=      -9995,
    ERROR_BAD_COMMAND=      -9994,
    ERROR_DIRECTORY=        -9993,
    ERROR_FILENAME=         -9992,
    ERROR_NOT_ANALOG_PIN=   -9991,
    ERROR_NOT_DIGITAL_PIN=  -9990,
    ERROR_NOT_INTERRUPT_PIN= -9989,
    ERROR_NOT_PWM_PIN=      -9988,
    ERROR_NOT_SERIAL_PIN=   -9987,
    ERROR_READ=             -9986,
    ERROR_WRITE=            -9985,
    ERROR_BAD_PARAM=        -9984,
    ERROR_INIT1=            -9983,
    ERROR_INIT2=            -9982,
    ERROR_INIT3=            -9981,
    ERROR_NO_DATA=          -9980,
    ERROR_NO_MEMORY=        -9979,
};

#endif // ERRORCODES_H
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13878
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I like the idea but I don't know if it would work in practice for all projects. I think every library could include such a list as it documents all errors in one place.

sort of best practice.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I like that you live by your motto.  :-) 

I think with feedback from the Arduino forum, you could have a consolidated error list that would cover 80% of the standard error conditions.  It would make it a lot easier to figure out how to use a new library - and it might remind library writers to check for common error conditions.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13878
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I changed two of my libs on the playground with error codes in the .h file

- http://arduino.cc/playground/Main/DHT11Lib -
- http://arduino.cc/playground/Main/DHTLib -

improved the readability of the example and I could remove some comments explaining magic numbers smiley
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

log on to your favorite unix box and look at /usr/include/sys/errno.h .  Then look up the perror() function.

Unix has been doing it this way for years.  Works quite well.  I'll be some form of errno.h and perror() would work out well for the arduino, too.

-j
Logged

Pages: [1]   Go Up
Jump to: