12.1.2 Object Exception Class
An object exception is an exception that is thrown by an object that is not part. The object exception that Delphi defines includes flow exception, print exception, graph exception, string list exception, etc.
12.1.2.1 Flow Anomaly Class
Stream exception classes include Estreamerror, Efcreateerror, Efopenerror, Efilererror, Ereaderror, Ewriteerror, and Eclassnotfound. Their structural relationships are as follows:
Estreamerror
|----------efcreateerror
|----------efopenerror
|----------efilererror
|---------ereaderror
|---------ewriteerror
|---------eclassnotfound
Figure 12.1 Flow anomaly Structure diagram
The stream exception is defined in the Classes Library unit.
The cause of the stream exception is shown in table 12.6.
Table 12.6 flow anomaly class and its cause
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Exception class causes
─────────────────────────────────
Estreamerror using the Loadfromstream method to read a stream has an error
Efcreateerror an error occurred while creating the file
Efopenerror an error occurred while opening the file
Efilererror tries to log in to an existing object again
Ereaderror Readbuffer Method cannot read a specific number of bytes
Ewriteerror WriteBuffer Method cannot write a specific number of bytes
Parts on the Eclassnotfound window are removed from the window's type definition
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
12.1.2.2 Print Exception class
Print Exception class Eprinter is raised when an error occurs on the print. It is defined in the Printers Library unit. For example, if your application tries to print to a nonexistent printer or if, for some reason, the print job cannot be delivered to the printer, a print exception is generated.
12.1.2.3 Graphics Exception class
The graph exception class is defined in the Graphic Library unit, including the Einvalidgraphic and Einvalidgraphicoperation categories.
Einvalidgraphic thrown when an application attempts to mount a graphic from a file that does not contain legitimate bitmaps, icons, meta files, or user-defined graphic types. For example, the following code:
Image1.Picture.LoadFromFile (' Readme.txt ');
Because Readme.txt does not contain a valid graphic, a Einvalidgraphic exception is thrown.
Einvalidgraphicoperation is raised when an attempt is made to illegally manipulate a graphic. For example, trying to change the size of an icon.
Var
Anicon:ticon;
Begin
Anicon: = ticon.create;
Anicon.loadfromfile (' C:\WINDOWS\DIRECTRY. ICO ');
Anicon.width: = 100; {Throws a graphics exception}
...
12.1.2.4 String List exception
String list exception estringlisterror, Elisterror raised when the user illegally manipulated the string list. Because many parts (such as Tlistbox,tmemo,ttabset,...) Have an important attribute of the Tstrings class, so string-list exceptions are useful in part-manipulation programming.
Estringlisterror exceptions typically occur when a string list crosses the line. For example, a list box that initializes the following:
LISTBOX1.ITEMS.ADD (' The ' the ' item ');
LISTBOX1.ITEMS.ADD (' Second item ');
LISTBOX1.ITEMS.ADD (' third item ');
The following actions can cause Estringlisterror exceptions:
LISTBOX1.ITEM[3]: = ' not Exist ';
str: = Listbox1.item [3];
Elisterror exceptions are typically raised in the following two cases:
1. When the duplicates property of the string list is set to Duperror, the application attempts to add a duplicate string;
2. An attempt was made to insert a string into a sorted string list.