📄 jvgexceptionhandler.pas
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvgExceptionHandler.PAS, released on 2003-01-15.
The Initial Developer of the Original Code is Andrey V. Chudin, [chudin att yandex dott ru]
Portions created by Andrey V. Chudin are Copyright (C) 2003 Andrey V. Chudin.
All Rights Reserved.
Contributor(s):
Michael Beck [mbeck att bigfoot dott com].
Burov Dmitry, translation of russian text.
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvgExceptionHandler.pas,v 1.19 2005/02/17 10:21:20 marquardt Exp $
unit JvgExceptionHandler;
{$I jvcl.inc}
{$I windowsonly.inc}
interface
uses
{$IFDEF USEJVCL}
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
{$ENDIF USEJVCL}
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, jpeg,
{$IFDEF USEJVCL}
JvTypes, JvComponent,
{$ENDIF USEJVCL}
JvgMailSlots, JvgSysInf;
type
TExceptionHandlerOption = (fehActiveDesignTime, fehActiveRunTime,
fehFileLogging, fehSupressExceptions, feScreenShots);
TExceptionHandlerOptions = set of TExceptionHandlerOption;
{$IFDEF USEJVCL}
EJvgHandlerException = class(EJVCLException);
{$ELSE}
EJvgHandlerException = class(Exception);
{$ENDIF USEJVCL}
{$IFDEF USEJVCL}
TJvgExceptionHandler = class(TJvComponent)
{$ELSE}
TJvgExceptionHandler = class(TComponent)
{$ENDIF USEJVCL}
private
FActive: Boolean;
FLogFileName: string;
FEMail: string;
FMailSlot: TJvgMailSlotClient;
FOptions: TExceptionHandlerOptions;
FScreenShotList: TList;
FSysInfo: TJvgSysInfo;
procedure MakeScreenShot(const ID: string);
procedure ShowMessage(E: Exception; const Msg: string);
protected
procedure OnException(Sender: TObject; E: Exception); virtual;
procedure Loaded; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Refresh;
procedure ProcessMessage(const ExceptionMessage, Msg, ID: string);
procedure Log_(const ID: string); overload;
procedure Log_(E: Exception); overload;
procedure Log_(E: Exception; const ID: string); overload;
procedure Raise_(const ID: string); overload;
procedure Raise_(E: Exception); overload;
procedure Raise_(E: Exception; const ID: string); overload;
procedure Raise_(E: Exception; const Msg, ID: string); overload;
procedure RaiseMessage(const Msg: string);
published
property Active: Boolean read FActive write FActive default True;
property EMail: string read FEMail write FEMail;
property LogFileName: string read FLogFileName write FLogFileName;
property MailSlot: TJvgMailSlotClient read FMailSlot write FMailSlot;
property Options: TExceptionHandlerOptions read FOptions write FOptions
default [fehActiveRunTime, fehFileLogging];
end;
{$IFDEF USEJVCL}
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvgExceptionHandler.pas,v $';
Revision: '$Revision: 1.19 $';
Date: '$Date: 2005/02/17 10:21:20 $';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
{$ENDIF USEJVCL}
implementation
uses
FileCtrl,
{$IFDEF USEJVCL}
JvConsts,
{$ENDIF USEJVCL}
JvgUtils, JvgFileUtils;
var
ExceptionHandler: TJvgExceptionHandler = nil;
procedure AssertErrorHandler_gl(const Msg, FileName: string;
LineNumber: Integer; ErrorAddr: Pointer);
begin
if Assigned(ExceptionHandler) then
ExceptionHandler.ProcessMessage(
'ExceptAddr=' + Format('%p', [ErrorAddr]) + sLineBreak +
'LineNumber=' + IntToStr(LineNumber) + sLineBreak +
'FileName=' + FileName
, 'internal JvgExceptionHandler message', '');
ExceptionClass := EAssertionFailed;
// E := CreateAssertException(Msg, FileName, LineNumber);
// RaiseAssertException(E, ErrorAddr, PChar(@ErrorAddr)+4);
end;
//=== { TJvgExceptionHandler } ===============================================
constructor TJvgExceptionHandler.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FActive := True;
FOptions := [fehActiveRunTime, fehFileLogging];
FLogFileName := '_errors_log.txt';
FScreenShotList := TList.Create;
end;
destructor TJvgExceptionHandler.Destroy;
begin
FScreenShotList.Free;
FSysInfo.Free;
Application.OnException := nil;
inherited Destroy;
end;
procedure TJvgExceptionHandler.OnException(Sender: TObject; E: Exception);
begin
if E is EJvgHandlerException then
Exit;
ProcessMessage(E.Message, '', '');
if not (fehSupressExceptions in Options) then
Application.MessageBox(PChar(E.Message),
PChar('Something has occured - ' + Application.Title),
MB_OK + MB_ICONSTOP);
end;
procedure TJvgExceptionHandler.Loaded;
begin
inherited Loaded;
if Active then
if ((csDesigning in ComponentState) and (fehActiveDesignTime in Options)) or
(not (csDesigning in ComponentState) and (fehActiveRunTime in Options)) then
begin
Application.OnException := OnException;
// 袜耱痤殛
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -