ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I have 2 complete different modules: a server and a client.
Client sends messages to the server, if server returns an error, client displays it on the output. For e.g. if some API say "sendto()" or "fopen" fails on the server side, i send the perror output to the client and it is displayed. But the error doesn't have any details like function name in which the call failed etc...
Similarly, on the client side, if any API fails, i just display the perror output.
Here's what i want to do:
1) Have a proper error module for showing/logging errors. This can be a single error handling API which will handle all errors.
2) Show a proper description of errors occuring at client side as well as server side. The errors should include function names and maybe some other details (not sure what else to show).
2) The error logging should be optional i.e. based on some environment variable or compilation flag, i should be able to disable the detailed error logging.
Now, i guess i can simply use "__FUNCTION__" macro for getting the current function name and "__LINE__" macro for getting the current line number.
Please suggest something...basically a sample structure of how i can achieve the above will be of great help and how can i disable error handling based on some flag/variable value?
Note that there isn't even a function name - but you can provide one if you wish. Also note that the file name is provided, not the program name. You can put some short name in to identify your program if you wish; otherwise if you look at a log file shared by different programs you can become a little confused. The exampe above also assumes sane filenames; interesting things happen if you give strange names to your .c files such as "%s%dSome_ridiculous_filename%x"
How would the function differentiate between an error code and a string? You'll be passing either a pointer to a string, or an integer. Would the function guess as to whether it should dereference the pointer or assume an error code?
If you are going to have various data types being passed, you need to encapsulate pass a type argument to indicate what type of data is being passed.
The drawback is that if you ever translate the error messages, you will have to re-write any software which parses the error messages and decides what to do. By including a numerical code first, you can check that programatically, and append a human-readable description after it.
i was thinking of using error codes in a header file. So, the error handling function will read the error code and display the appropriate message. I can always add more error codes and strings to the header later...