Pages: [1]   Go Down
Author Topic: ArduinoError: Error handling and debug library  (Read 359 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, when I learned C, I  (Learned it the hard way). One of the coolest functions he made were (Zed's Awesome Debug Macros), which are a fantastic way to simultaniously handle error checking and debugging in your program.

Well, now that I've gotten back into programing the Arduino, I decided to port this and make it much better. Check out my library (and all updated releases) here:
Github Repository

Code:
// ### Intended Use:
// There are many times where you want to do error checking and simultaniously provide debugging.
// This library helps significantly. Errors are automatically printed if DEBUG is defined.
// This library offers two ways to deal with errors, documented below:
// return checks     -- these do all your logging for you and set derr. (the global error variable).
//                        They then return R.
//                        these are intended for "simple use" cases, where you do not need to
//                        do any error handling (like send special error messages, close ports,
//                        etc)
// goto error checks -- these do your logging, etc and then "goto error;" where you can do error
//                        handling like closing ports, etc.

If you load up the sketch and run the example, you will get output like this:
(note that I am imputing 5 and then a character ('k' I think).

Code:
Input Int:
:: DBG: (0 errorhandling_ex1.ino:28)| 35 1
:: DBG: (0 errorhandling_ex1.ino:30)| outint:5
Output: 5
Input Int:
:: DBG: (0 errorhandling_ex1.ino:28)| 61 0
:: [ERR](50 errorhandling_ex1.ino:16)| (50:TypeErr)97
:: DBG: (50 errorhandling_ex1.ino:30)| outint:-1
:: [ERR](50 errorhandling_ex1.ino:31)| (253:NoNew)
:: [ERR](50 errorhandling_ex1.ino:40)| (253:NoNew)
:: DBG: (50 errorhandling_ex1.ino:45)| Caught Error
:: [ERR](252 errorhandling_ex1.ino:46)| (252:Cleared Error)
Input Int:

If I comment out "#define DEBUG":
Code:
Doing dbg test
Input Int:
Output: 5
Input Int:
Output: -1
Input Int:

As you can see, it shows the type of log, whether there is an error (first number), the file name : line number, and then the errno and the corresponding string for it (defined by this function). Finally, some of them print an output as well.

Error checking and helpful debugging messages given by a line of code as small as "assert_return(isint(c), -1);"!  Yes please!   smiley smiley smiley

Current Issues
You must include SoftwareSerial.h -- I can't figure out why my inclusion in the .h file is not sufficient, can someone help me with this?
« Last Edit: December 09, 2013, 07:08:02 pm by cloudformdesign » Logged

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

I have updated the library. There are now "return" macros so that goto's are not necessary for simple functions.

In addition, I have fixed several bugs and renamed the files.  Documentation has also been added.

Give it a try and let me know what you think!
Logged

Pages: [1]   Go Up
Jump to: