msgexcept.pas

来自「Delphi MsgCommunicator 2-10 component.I 」· PAS 代码 · 共 72 行

PAS
72 行
字号
{$I MsgVer.inc}

unit MsgExcept;

interface

uses SysUtils, Classes,
 {$IFDEF DEBUG_LOG}
     MsgDebug,
 {$ENDIF}
     MsgConst;

type


////////////////////////////////////////////////////////////////////////////////
//
// EMsgException
//
////////////////////////////////////////////////////////////////////////////////


  EMsgException = class( Exception )
  public
    NativeError: Integer;

    constructor Create(NativeErrorCode: Integer; ErrorMsg: String); overload;
    constructor Create(NativeErrorCode: Integer; ErrorMsg: String; const Args: array of const); overload;
  end; // EMsgException

implementation


//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
constructor EMsgException.Create(NativeErrorCode: Integer; ErrorMsg: String);
var
  ErMessage: string;
begin
  NativeError := NativeErrorCode;
  ErMessage := ErrorMsg;
  ErMessage := ErMessage + ' - Native error: '+ Format('%.5d',[NativeErrorCode]);
  inherited Create(ErMessage);
end; // Create


//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
constructor EMsgException.Create(NativeErrorCode: Integer; ErrorMsg: String; const Args: array of const);
var
  ErMessage: string;
begin
  NativeError := NativeErrorCode;
  try
    ErMessage := Format(ErrorMsg, Args);
  except
    ErMessage := ErrorMsg + ' Arguments are invalid!';
  end;
  ErMessage := ErMessage + ' - Native error: ' + Format('%5d',[NativeErrorCode]);
  inherited Create(ErMessage);
end; // Create

initialization

{$IFDEF DEBUG_LOG_INIT}
aaWriteToLog('MsgComBaseEngine> initialized');
{$ENDIF}

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?