各种错误都有标准数字吗? [英] Are there standard numbers for various errors?

查看:77
本文介绍了各种错误都有标准数字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很久以前,在一个遥远的地方,有一个名为DOS的OS,

有标准的数字返回码。无论使用何种编程语言,都应该使用相同的错误返回码。见
http://www.felgall.com/doserr.htm获取更大的列表。这样开始...


#1无效的功能代码

#2找不到文件

#3未找到路径

#4无句柄可用,打开文件太多

#5访问被拒绝

#6文件句柄无效

根据我的帖子主题,是否有任何错误标准

返回C代码?现在,我正在使用1缺少更好的东西,

除非有一些超越原因。这是一个典型的

计划的开始...


#include< stdio.h>

int main(int argc,char * argv [])

{

unsigned long int accumulator,b1 [256];

float percent;

int i,pixel;

FILE * input_file,* output_file;


if(argc!= 3){

printf("正确用法:\ n%s input_filename output_filename \ n",argv [0]);

返回1;

}

if((input_file = fopen(argv [1]," rb"))== NULL){

printf("打开%s输入错误\\ n",argv [1]);

返回1;

}

if((output_file = fopen(argv [2], " w"))== NULL){

printf("错误打开%s表示输出\ n",argv [2]);

返回1 ;


-

Walter Dnes;我的电子邮件地址是* ALMOST *,如 wz*******@waltdnes.org

删除z得到我的真实地址。如果被阻止,请按照550消息末尾的说明进行操作。

解决方案

" Walter Dnes(删除''z'以获取我的真实地址) < WZ ******* @ waltdnes.org>写道:

很久以前,在一个遥远的地方,有一个名为DOS的操作系统


实际上有几个操作系统叫DOS;我想你是想想一个名为MS-DOS的b $ b。

有标准的数字返回码。无论使用何种编程语言,都应该使用相同的错误返回码。见
http://www.felgall.com/doserr.htm获取更大的列表。这样开始......

#1无效的功能代码
#2找不到文件
#3未找到路径
#4无可用句柄,太多打开文件
#5访问被拒绝
#6无效文件句柄

根据我的帖子主题,是否有任何标准的错误
返回C代码?现在,我正在使用1缺少更好的东西,
除非有一些超越原因。这是一个典型的
程序的开始...




标准定义的唯一程序返回代码是

如果一个程序成功退出它应该返回0或EXIT_SUCCESS,并且

如果失败它应该返回EXIT_FAILURE。

宏EXIT_SUCCESS和EXIT_FAILURE在<中定义; stdlib.h>


-

<在这里插入你最喜欢的报价。>

Erik Trulsson
er******@student.uu.se


>很久以前,在一个遥远的地方,有一个名为DOS的操作系统


有很多操作系统叫做DOS。他们中的许多人与微软或英特尔硬件无关。

有标准的数字返回码。无论使用何种编程语言,都应该使用相同的错误返回码。见
http://www.felgall.com/doserr.htm获取更大的列表。这样开始......

#1无效的功能代码
#2找不到文件
#3未找到路径
#4无可用句柄,太多打开文件
#5访问被拒绝
#6无效文件句柄


我知道程序退出代码的大量使用(在COMMAND.COM中使用

批处理脚本)不符合此用法。许多脚本

会运行一个程序,它会抛出一个菜单并从用户那里得到一个回答

,然后返回用户的选择。退出代码然后

告诉批处理脚本用户的选择,这通常使用上面的小的

数字,并且脚本执行了所要求的内容。 />
选择可能类似于:(1)安装,(2)卸载,

(3)显示帮助文件,(4)退出

As根据我的帖子的主题,是否有任何标准的错误
返回C代码?




C有一些错误代码通常存放在errno中

之后出现错误,例如ERANGE和EDOM。许多实现,例如

UNIX,都会增加更多。这些代码没有标准的

整数值; ERANGE到处都有ERANGE的值,但不能保证ERANGE == 0xdeadbeef在任何地方都是
。有时

errno中的代码或程序本地扩展名

用作函数返回值(其中0表示成功)。


程序的退出值不是错误代码本身。

标准值用作exit()的参数或从

main()返回的是EXIT_SUCCESS,0和EXIT_FAILURE。


请注意,程序可能因多个原因导致异常终止,包括操作系统可能会考虑的结果是否为
是否为错误:访问授予,或找到文件可能是致命的

错误(例如,某些程序拒绝覆盖现有文件

并专门为此测试)。

终止一个根本不处理操作系统错误的程序也有很多原因:

缺失或冲突的选项或命令行参数,语法

输入错误,数据库密码错误等等。


请注意,告诉用户通常更重要*什么*

失败然后*为什么*。如果程序说foobar.txt不能打开用于写入的
,用户通常有更好的机会来解决问题。而不是说许可被拒绝没有

说*什么*许可被拒绝。


Gordon L. Burditt


周六,2004年5月15日22:34:48 +0000,Erik Trulsson写道:

" Walter Dnes(删除''z''以获取我的真实地址)" < WZ ******* @ waltdnes.org>写道:

很久以前,在一个遥远的地方,有一个名为DOS的操作系统实际上有几个操作系统叫做DOS;我想你是在思考名为MS-DOS的那个。




或FreeDOS或OpenDOS或DR-DOS或PC-DOS或QDOS ......

标准定义的唯一程序返回码是
如果一个程序成功退出它应该返回0



[snip]


这总是让我很困惑:鉴于在VMS中,返回代码为0

表示执行不成功,编译器对

main()以return 0结尾;? (这只是令人困惑,因为

编译器必须与程序员所说的做什么相反,这对于程序员来说意味着什么,这在我看来是非常不像C的。 )


-

yvoregnevna gjragl-guerr gjb-gubhfnaq guerr ng lnubb qbg pbz

给我发电子邮件,rot13和转换拼写数字到数字形式。

让黑客微笑让黑客微笑。


A long time ago, in a place far away, there was an OS called DOS that
had standard numeric return codes. Regardless of the programming
language used, the same error return codes were supposed to be used. See
http://www.felgall.com/doserr.htm for a larger list. It starts like so...

# 1 Invalid Function Code
# 2 File Not Found
# 3 Path Not Found
# 4 No Handles Available, Too Many Open Files
# 5 Access Denied
# 6 Invalid File Handle

As per the subject of my post, are there any standards for error
return codes in C? Right now, I''m using 1 for lack of anything better,
unless there''s some over-riding reason. Here''s the start of a typical
program...

#include <stdio.h>
int main(int argc, char *argv[])
{
unsigned long int accumulator, b1[256];
float percent;
int i, pixel;
FILE *input_file, *output_file;

if(argc != 3){
printf(" Correct usage:\n %s input_filename output_filename\n", argv[0]);
return 1;
}
if((input_file = fopen(argv[1], "rb")) == NULL){
printf("Error opening %s for input\n", argv[1]);
return 1;
}
if((output_file = fopen(argv[2], "w")) == NULL){
printf("Error opening %s for output\n", argv[2]);
return 1;

--
Walter Dnes; my email address is *ALMOST* like wz*******@waltdnes.org
Delete the "z" to get my real address. If that gets blocked, follow
the instructions at the end of the 550 message.

解决方案

"Walter Dnes (delete the ''z'' to get my real address)" <wz*******@waltdnes.org> wrote:

A long time ago, in a place far away, there was an OS called DOS that
There have actually been several OS called DOS; I guess you are
thinking of the one named MS-DOS.
had standard numeric return codes. Regardless of the programming
language used, the same error return codes were supposed to be used. See
http://www.felgall.com/doserr.htm for a larger list. It starts like so...

# 1 Invalid Function Code
# 2 File Not Found
# 3 Path Not Found
# 4 No Handles Available, Too Many Open Files
# 5 Access Denied
# 6 Invalid File Handle

As per the subject of my post, are there any standards for error
return codes in C? Right now, I''m using 1 for lack of anything better,
unless there''s some over-riding reason. Here''s the start of a typical
program...



The only program return codes that are defined by the standard are that
if a program exits successfully it should return 0 or EXIT_SUCCESS, and
if it fails it should return EXIT_FAILURE.
The macros EXIT_SUCCESS and EXIT_FAILURE are defined in <stdlib.h>


--
<Insert your favourite quote here.>
Erik Trulsson
er******@student.uu.se


> A long time ago, in a place far away, there was an OS called DOS that

There were a lot of OSs called DOS. Many of them had nothing to do
with Microsoft or with Intel hardware.

had standard numeric return codes. Regardless of the programming
language used, the same error return codes were supposed to be used. See
http://www.felgall.com/doserr.htm for a larger list. It starts like so...

# 1 Invalid Function Code
# 2 File Not Found
# 3 Path Not Found
# 4 No Handles Available, Too Many Open Files
# 5 Access Denied
# 6 Invalid File Handle
I know of a lot of uses of program exit codes (used in COMMAND.COM
batch scripts) that did not conform to this usage. Many scripts
would run a program which would throw up a menu and get an answer
from the user, then return the user''s choice. The exit code then
told the batch script the user''s choice, which often used small
numbers like the above, and the script did what was asked.
Choices might be something like: (1) install, (2) uninstall,
(3) display help file, (4) quit
As per the subject of my post, are there any standards for error
return codes in C?



C has a few error codes that are typically deposited in errno after
an error, such as ERANGE and EDOM. Many implementations, such as
UNIX, add a lot more of them. These codes do not have standard
integer values; ERANGE has a value of ERANGE everywhere, but it''s
not guaranteed that ERANGE == 0xdeadbeef anywhere. Sometimes
the codes in errno or extensions of these local to the program
are used as function return values (where 0 indicates success).

Exit values from a program are not "error codes" per se. The
standard values for use as an argument of exit() or return from
main() are EXIT_SUCCESS, 0, and EXIT_FAILURE.

Note that a program might terminate abnormally for a number of
reasons, including the negative of what the OS might consider to
be an error: "Access Granted", or "File Found" might be a fatal
error (for example, some programs refuse to overwrite existing files
and specially test for this). There are also plenty of reasons for
terminating a program that don''t deal with an OS error at all:
missing or conflicting options or command-line arguments, syntax
error in the input, bad database password, etc.

Note that it''s often much more important to tell the user *WHAT*
failed then *WHY*. A user usually has a better chance of figuring
the problem out if the program says that "foobar.txt cannot be
opened for writing" than if it says "permission denied" without
saying *WHAT* permission was denied.

Gordon L. Burditt


On Sat, 15 May 2004 22:34:48 +0000, Erik Trulsson wrote:

"Walter Dnes (delete the ''z'' to get my real address)" <wz*******@waltdnes.org> wrote:

A long time ago, in a place far away, there was an OS called DOS that
There have actually been several OS called DOS; I guess you are
thinking of the one named MS-DOS.



Or FreeDOS or OpenDOS or DR-DOS or PC-DOS or QDOS ...
The only program return codes that are defined by the standard are that
if a program exits successfully it should return 0


[snip]

This has always kind of confused me: Given that in VMS, a return code of 0
indicates an unsuccessful execution, what does the compiler do with a
main() that ends with return 0;? (This is only confusing because the
compiler would have to contradict what the programmer said to do what the
programmer meant, something distinctly un-C-like to my mind.)

--
yvoregnevna gjragl-guerr gjb-gubhfnaq guerr ng lnubb qbg pbz
To email me, rot13 and convert spelled-out numbers to numeric form.
"Makes hackers smile" makes hackers smile.


这篇关于各种错误都有标准数字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆