RSS订阅 | 匿名投稿
您的位置:网站首页 > 程序 > 正文

delphi TApplication.OnException

作者:admin 来源: 日期:2018/1/23 11:05:58 人气: 标签:

代码文件:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    procedure AppException(Sender: TObject; E: Exception);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

type   
  MyException = Class(Exception);

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnException := AppException;
  Button1.Caption := '激发一个异常';
end;

procedure TForm1.AppException(Sender: TObject; E: Exception);
begin
  Application.ShowException(E);
  Application.Terminate;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  raise MyException.Create('发生异常, 将要退出!');
end;

end.

读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址:
下一篇:没有资料