您现在的位置:首页 >> 基础算法 >> window基础 >> 内容

Delphi写的精简的异常处理机制

时间:2011/9/3 15:29:57 点击:

  核心提示:unit uInitExceptions;{Streamlined By BinJian in sleepless.}interfacetype{ Exceptions }Exception = cl...
unit uInitExceptions;
{
Streamlined By BinJian in sleepless.
}
interface
 
type
  { Exceptions }
  Exception = class(TObject)
  private
    FMessage: string;
  public
    constructor Create(const Msg: string);
  end;
  ExceptClass = class of Exception;
 
implementation
 
{ Exception class }
 
constructor Exception.Create(const Msg: string);
begin
  FMessage := Msg;
end;
 
function GetExceptionClass(P: Pointer): ExceptClass;
begin
  Result := Exception;
end;
 
procedure ErrorHandler(ErrorCode: Byte; ErrorAddr: Pointer); export;
var
  E: Exception;
begin
  E := nil;
  raise E at ErrorAddr;
end;
 
function GetExceptionObject(P: Pointer): Exception;
begin
  Result := Exception.Create('Exception happenned.');
end;
 
procedure ExceptHandler(ExceptObject: TObject; ExceptAddr: Pointer); far;
begin
  Halt(1);
end;
 
procedure InitExceptions;
begin
  ErrorProc := ErrorHandler;
  ExceptProc := @ExceptHandler;
  ExceptionClass := Exception;
 
{$IFDEF MSWINDOWS}
  ExceptClsProc := @GetExceptionClass;
  ExceptObjProc := @GetExceptionObject;
{$ENDIF}
end;
 
initialization
  InitExceptions;
end.

作者:BinJian 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号