DIE Methods
If you are like me, you aren't a huge fan of C++ exception handling, and you use return codes.
If you do, you might often return 0 as "OK" and -1 as "BAD" from a function that returns an int. To return -1 from such a function, and print an error to the console, just use DIE ("Some error message!")
Or, you might return not-null as "Here's a pointer to what you wanted" as "OK" and null as "BAD from a function that returns a pointer. For that, use PDIE ("Some other error message")
What about if you are returning a "" as a problem result, and a non-empty string otherwise? Use SDIE.
What if you are returning a ref template (see below) to an object? The messy one is RDIE, which is "ref" die (see below); For that you have to define a "NullRef" in the function you are going to use.
No return type at all (i.e., a void myfunc())? use VDIE.
There is also "WARN" which prints a warning, "TRACE" which prints a debug message, "CONTINUE" which prints a message and "continues" (i.e., for use in loops) or "BREAK" which prints a message and breaks (again, use in loops).
CAVEAT: You have to call die_init ("error.log") before you call any of the die methods.
| Attachment | Size |
|---|---|
| die.h | 745 bytes |
| die.cpp | 126 bytes |