Skip to content

Easy object-oriented way to create and handle errors for embedded systems

License

Notifications You must be signed in to change notification settings

STashakkori/EmbedErr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EmbedErr

Easy object-oriented way to create and handle errors for embedded systems

The way it works is like this:

Error objects hold this information:

const uint16_t errorCode;
const std::string objectID;
std::chrono::system_clock::time_point timestamp;

Have a vector of Error objecst somewhere upstream in your code:

std::vector<std::shared_ptr<Error>> errors;

Implement Errorable inteface in class you want to track errors in:

class MyClass : public Errorable {
  // Implementation of the class
};

Then push errors to that class whenever you want in the code:

ExampleClass example;
example.pushError(errors, 3);

Write a handler for the errors or for simple testing:

for (auto error : errors) {
  error->print();
  error->log();
}

And the error can get logged as well using log.h:

Error: code: 3
         id: class ExampleClass
       time: 2023-08-31 21:01:07

Notice that the errors with automagically know the source of the error with a time stamp.

It is up to the class implementor to know what the error codes mean but there is no chance of code clashing this way because they organized by the source object. Easy, simple, but kinda nice right? Hopefully its useful to somebody somewhere

If using pure ANSI C, then you could implement something similar by passing down a pointer to an integer in every function and then have the caller handle. This keeps your returns open for your intended use.

About

Easy object-oriented way to create and handle errors for embedded systems

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages