VCL applications handle most exceptions that your code doesn't specifically handle by displaying a message box that shows the message string from the exception object. You can also define "silent" exceptions that do not, by default, cause the application to show the error message.
Silent exceptions are useful when you don't intend to report an exception to the user, but you want to abort an operation. Aborting an operation is similar to using the Break or Exit procedures to break out of a block, but can break out of several nested levels of blocks.
Silent exceptions all descend from the standard exception type EAbort. The default exception handler for VCL applications displays the error-message dialog box for all exceptions that reach it except those descended from EAbort.
procedure TForm1.Button1Click(Sender: TObject); var I, J: Integer; begin for I := 1 to 10 do{ loop ten times } for J := 1 to 10 do {loop ten times } begin ListBox1.Items.Add(IntToStr(I) + IntToStr(J)); if I = 7 then Abort;{ abort after the 7th iteration of outer loop} end; end;
void __fastcall TForm1::Button1Click(TObject* Sender) { for (int i = 1; i <= 10; i++) // loop ten times for (int j = 1; j <= 10; j++) // loop ten times { ListBox1->Items->Add(IntToStr(i) + IntToStr(j)); if (i == 7) Abort(); // abort after 7th iteration of outer loop } }
Note that in this example, Abort causes the flow of execution to break out of both the inner and outer loops, not just the inner loop.
VCL Exception Classes
Default Exception Handling in VCL
Defining Your Own VCL Exceptions
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|