Error handling and polymorphism
Posted
by Neeraj
on Stack Overflow
See other posts from Stack Overflow
or by Neeraj
Published on 2010-03-24T20:53:24Z
Indexed on
2010/03/24
21:03 UTC
Read the original article
Hit count: 234
c++
|error-handling
I have an application with some bunch of code like this:
errCode = callMainSystem();
switch (errCode){
case FailErr: error("Err corresponding to val1\n");
case IgnoreErr: error("Err corresponding to val2\n");
...
...
default: error("Unknown error\n");
}
The values are enum constants. Will it make some sense to have something like:
// Error* callMainSystem()
... Some code
return FaileErr(); // or some other error
// handling code
Error* err = callMainSystem();
err->toString();
The Error class may be made singleton as it only has to print error messages.
What are the pros and cons of above methods,size is an important criteria as the application needs to be supported on embedded devices as well.
P.S: I don't want to use exception handling because of portability issues and associated overheads.
© Stack Overflow or respective owner