---------
Will you handle error information? Oh, it is not a simple output. Look into the example below:
IF (p == null) {
Printf ("Err: The Pointer is NULL / N);
}
Say goodbye to the programming of the student era. This programming is very disadvantageous for maintenance and management, error information, or prompt information, should be unified, not like the above, write into a "hard coded". Article 10 describes a part of this in this regard. If you want to manage the error message, you have the following processing:
/ * Statement error code * /
#define err_no_error 0 / * no error * /
#define err_open_file 1 / * Open file Error * /
#define err_send_mesg 2 / * sending a message error * /
#define err_bad_args 3 / * Bad arguments * /
#define err_mem_none 4 / * memeroy is not enough * /
#define err_serv_down 5 / * Service Down Try Later * /
#define err_unknow_info 6 / * unknow information * /
#define err_socket_err 7 / * Socket Operation Failed * /
#define err_persermission 8 / * permission Denied * /
#define err_bad_format 9 / * Bad Configuration File * /
#define err_time_out 10 / * Communication Time OUT * /
/ * Statement error message * /
Char * errmsg [] = {
/ * 0 * / "no error",
/ * 1 * / "open file error",
/ * 2 * / "failed in sending / receiving a message,
/ * 3 * / "Bad Arguments",
/ * 4 * / "Memeroy Is Not Enough",
/ * 5 * / "service is down; try lat),
/ * 6 * / "unknow information",
/ * 7 * / "a socket Operation Has Failed",
/ * 8 * / "permission Denied",
/ * 9 * / "Bad Configuration File Format",
/ * 10 * / "Communication Time Out",
}
/ * Declare error code global variable * /
Long errno = 0;
/ * Print an error message function * /
Void Perror (Char * Info)
{
IF (info) {
Printf ("% s:% s / n", info, errmsg [errno]);
Return;
}
Printf ("Error:% S / N", errmsg [errno]);
This is basically ANSI's error handling detail, so you can do this when you have an error in your program:
Bool Checkpermission (Char * Username)
{
IF (STRCPY (UserName, "root")! = 0) {
Errno = err_persermission_ndenied;
Return (False);
}
...
}
Main ()
{
...
if (! Checkpermission (UserName) {
"" main () ");
}
...
}
One is a common, and some wrong information processing, so that the same information is the same, the unified user interface, without the failure of the file, the A programmer has an information, and the programmer has an information. And do this, it is very easy to maintain. The code is also easy to read.
Of course, the object must be reversed, nor is therefore necessary to put all the outputs in Errmsg, extracting more important error messages or prompting information is the key, but even though, this also includes most of the information.