2023年12月7日发(作者:)

第14周 Freepascal错误代码一览表

任何一个天才都不敢说,他编的程序是100%正确的。几乎每一个稍微复杂一点的程序都必须经过反复的调试、修改,最终才完成。所以说,程序的调试是编程中的一项重要技术。Free Pascal

IDE提供了很强大的调试功能,能很方便的找出程序的错误。

1、程序错误

(1)编译错误:即语法错误。如:命令错写,少分号等等。此种错误在程序编译执行就能发现,而把光标停留在错误行上,并显示出错误信息,由用户修改。

(2)运行错误:如果没有语法错误。则程序可以运行,但在运行过程中也有可能出现错误,如程序结构不合理,打印语句错误等。此时,程序将中止运行,光标停留在错误语句处,并显示错误信息,等待用户修改。

(3)逻辑错误:如:程序递归出口设置不正确,逻辑判断设置错误,这样程序虽然能够正常运行,但运行结果却不正确,这是用户最难发现有错误,也是最难查找的错误,此时计算机也无任何错误信息。

一、程序调试

根据下面的错误代码表,检查、、、程序运行过程中的错误代码,并尝试解决。

二、实验设计。编制程序,尝试模拟下面运行错误代码出现的情况。

205 Floating point overflow

浮点数上溢

你试图使用或产生一个太大实数.

206 Floating point underflow

你试图使用或产生一个太小实数.

207 Invalid floating point operation

错误的浮点数操作

可能是你开平方根或者对数时使用负数.

DOS 错误代码

1无效DoS功能号

2文件末找到

3路径未找到

4打开文件过多

5禁止文件存取

6无效文件句柄

12无效文件存取代码

15无效驱动器号

16不能删除当前日录

17不能跨驱动器改文件名

严重错误

150磁盘写保护

15l未知单元

152驱动器未准备好

153未知命令

154数据CRC校验错

155驱动器请求的结构长度错

156磁盘定位错

157未知媒介类型

158扇区末找到

159打印机缺纸

160设备写失败

161设备读失败

162硬件故障

163 未知

Free Pascal Run Time Errors 运行错误对照表

1 Invalid function number

You tried to call a DOS function which doesn't exist.

2 File not found

You can get this error when you tried to do an operation on a file which doesn't exist.

3 Path not found

You can get this error when you tried to do an operation on a file which doesn't exist, or when you

try to change to, or remove a directory that doesn't exist, or try to make a subdirectory of a

subdirectory that doesn't exist.

4 Too many open files

When attempting to open a file for reading or writing, you can get this error when your program

has too many open files.

5 File access denied

You don't have access to the specified file.

6 Invalid file handle

200被零除

20l范围检查错

202堆栈溢出错

203堆溢出错

204无效指针操作

205浮点上溢出

206浮点下溢出

207无效浮点运算

208未安装覆盖管理程序

209覆盖文件读错

210对象未初始化

2ll调用抽象方法

212流登计错

213集合下标越界

214集合溢出

致命错误

I/O错误

100磁盘读错误

101磁盘写错误

102文件变量末赋值

103文件未打开

104文件未用输入方式打开

105文件末用输出方式打开

106无效数字格式 If this happens, the file variable you are using is trashed; it indicates that your memory is

corrupted.

12 Invalid file access code

This will happen if you do a reset or rewrite of a file when FileMode is invalid.

15 Invalid drive number

The number given to the Getdir function specifies a non-existent disk.

16 Cannot remove current directory

You get this if you try to remove the current diirectory.

17 Cannot rename across drives

You cannot rename a file such that it would end up on another disk or partition.

100 Disk read error

DOS only. An error occurred when reading from disk. Typically when you try to read past the end

of a file.

101 Disk write error

DOS only. Reported when the disk is full, and you're trying to write to it.

102 File not assigned

This is reported by Reset, Rewrite, Append, Rename and Erase, if you call them with an unassigne

function as a parameter.

103 File not open

Reported by the following functions : Close , Read, Write, Seek, EOf, FilePos, FileSize, Flush,

BlockRead, and BlockWrite if the file isn't open.

104 File not open for input

Reported by Read, BlockRead, Eof, Eoln, SeekEof or SeekEoln if the file isn't opened with Reset.

105 File not open for output

Reported by write if a text file isn't opened with Rewrite.

106 Invalid numeric format

Reported when a non-numerice value is read from a text file, when a numeric value was expected.

150 Disk is write-protected

(Critical error, DOS only.)

151 Bad drive request struct length

(Critical error, DOS only.)

152 Drive not ready

(Critical error, DOS only.)

154 CRC error in data

(Critical error, DOS only.)

156 Disk seek error

(Critical error, DOS only.)

157 Unknown media type

(Critical error, DOS only.)

158 Sector Not Found

(Critical error, DOS only.)

159 Printer out of paper

(Critical error, DOS only.)

160 Device write fault (Critical error, DOS only.)

161 Device read fault

(Critical error, DOS only.)

162 Hardware failure

(Critical error, DOS only.)

200 Division by zero

You are dividing a number by zero.

201 Range check error

If you compiled your program with range checking on, then you can get this error in the following

cases:

An array was accessed with an index outside its declared range. 数组越界访问

You're trying to assign a value to a variable outside its range (for instance a enumerated type). 超出变量范围,例如i:=32768;其中i为integer类型

202 Stack overflow error

The stack has grown beyond itss maximum size. This error can easily occur if you have recursive

functions.

203 Heap overflow error

The heap has grown beyond its boundaries, ad you are rying to get more memory. Please note that

Free Pascal provides a growing heap, i.e. the heap will try to allocate more memory if needed.

However, if the heap has reached the maximum size allowed by the operating system or hardware,

then you will get this error.

204 Invalid pointer operation

This you will get if you call dispose or Freemem with an invalid pointer (notably, Nil)

205 Floating point overflow

You are trying to use or produce too large real numbers.

206 Floating point underflow

You are trying to use or produce too small real numbers.

207 Invalid floating point operation

Can occur if you try to calculate the square root or logarithm of a negative number.

210 Object not initialized

When compiled with range checking on, a program will report this error if you call a virtal method

without having initialized the VMT.

211 Call to abstract method

Your program tried to execute an abstract virtual method. Abstract methods should be overridden,

and the overriding method should be called.

212 Stream registration error

This occurs when an invalid type is registered in the objects unit.

213 Collection index out of range

You are trying to access a collection item with an invalid index. (objects unit)

214 Collection overflow error

The collection has reached its maximal size, and you are trying to add another element. (objects

unit)

215 数字超出范围(例如3000000000超出长整形范围)

216 General Protection fault You are trying to access memory outside your appointed memory.

217 Unhandled expetion occurred

An exception occurred, and there was no exception handler present. The sysutils unit installs a

default exception handler which catches all excpetions and exits gracefully.

Pascal定义了五个标准整数类型,如下表所示:

类型

Shortint(短整型)

Integer (整型)

Longint(长整型)

Byte (字节型)

Word (字型)

取值范围

-128..127

-32768..32767

-2147483648..2147483647

0..255

占字节数

1

2

4

1

格式

带符号8位

带符号16位

带符号32位

无符号8位

无符号16位

0..65535 2

在前面程序中常用的数据类型除整数类型,还有实数类型。Pascal 还定义了五个标准实类型

Real

Single

Double

Extended

Comp

取值范围

2.9×10-39~1.7×1038

1.5×10~3.4×10

5.0×101.9×10-324-4538数类型,列表所示如下:

占字节数

6

4

8

10

8

有效数字

7~8位

11~12位

15~16位

19~20位

19~20位

~1.7×10

38308-495163~1.1×104932

-2+1~2-1