RAD Studio VCL Reference
|
Instantiates an instance of an exception with a simple message string.
constructor Create(const Name: string);
__fastcall ECorbaUserException(const AnsiString Name);
Call Create to construct an exception object with a simple message string.
Msg is the string containing the runtime error message to display in the exception dialog box. Msg can be a hard-coded string, or can be a function call that returns a string.
C++ Examples:
/* The following example creates a directory ‘C:\temp’ if it does not already exist. } */ #include <Filectrl.hpp> void __fastcall TForm1::Button1Click(TObject *Sender) { if (!DirectoryExists("c:\\temp")) { if (!CreateDir("C:\\temp")) throw Exception("Cannot create c:\\temp directory."); } if (!CreateDir("C:\\temp")) throw Exception("The c:\\temp directory already exists."); }
Delphi Examples:
{ The following example creates a directory ‘C:\temp’ if it does not already exist. } uses FileCtrl; procedure TForm1.Button1Click(Sender: TObject); begin if not SysUtils.DirectoryExists('C:\temp') then if not CreateDir('C:\temp') then raise Exception.Create('Cannot create C:\temp'); if not CreateDir('C:\temp') then raise Exception.Create('Cannot create C:\temp again!'); end;
{ In addition to displaying the exception message, which happens by default, the following code shuts down the application when an exception is not caught and handled. AppException should be declared a method of TForm1. } procedure TForm1.FormCreate(Sender: TObject); begin Application.OnException := AppException; end; procedure TForm1.AppException(Sender: TObject; E: Exception); begin Application.ShowException(E); Application.Terminate; end; procedure TForm1.Button1Click(Sender: TObject); begin raise EPasswordInvalid.Create('Incorrect password entered'); end;
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|