From 27b6f1c5a3df64cc7bab43aa66f3d2dee31aec71 Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 18 May 2020 07:40:35 +0000 Subject: [PATCH] * use reference to for exception handlers --- demo/errorhandler/errordemo.lpr | 4 ++-- packages/rtl/sysutils.pas | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/demo/errorhandler/errordemo.lpr b/demo/errorhandler/errordemo.lpr index 7b1ef36..c27ea99 100644 --- a/demo/errorhandler/errordemo.lpr +++ b/demo/errorhandler/errordemo.lpr @@ -65,7 +65,7 @@ Procedure TErrorApp.Run; begin // This will only work for the main program if you have set showUncaughtExceptions before rtl.run(); - // TJSHtmlButtonElement(Document.getElementById('btnhook')).OnClick:=@DoHook; + TJSHtmlButtonElement(Document.getElementById('btnhook')).OnClick:=@DoHook; // These will not be caught (yet) TJSHtmlButtonElement(Document.getElementById('btn')).OnClick:=@DoRaise; // Uncomment this to set default exception handlers @@ -73,7 +73,7 @@ begin // Uncomment these to set special exception handlers // SetOnUnCaughtExceptionHandler(@DoPascalException); - // SetOnUnCaughtExceptionHandler(@DoJSException); + SetOnUnCaughtExceptionHandler(@DoJSException); // Various ways to raise an exception. // DoRaiseJS; diff --git a/packages/rtl/sysutils.pas b/packages/rtl/sysutils.pas index e7d1f89..c94595b 100644 --- a/packages/rtl/sysutils.pas +++ b/packages/rtl/sysutils.pas @@ -315,8 +315,8 @@ type TOnGetEnvironmentString = function(Index: Integer): String; TOnGetEnvironmentVariableCount = function: Integer; TShowExceptionHandler = Procedure (Const Msg : String); - TUncaughtPascalExceptionHandler = Procedure(aObject : TObject); - TUncaughtJSExceptionHandler = Procedure(aObject : TJSObject); + TUncaughtPascalExceptionHandler = reference to Procedure(aObject : TObject); + TUncaughtJSExceptionHandler = reference to Procedure(aObject : TJSObject); var OnGetEnvironmentVariable: TOnGetEnvironmentVariable; @@ -326,10 +326,11 @@ var OnShowException : TShowExceptionHandler = nil; // Set handlers for uncaught exceptions. These will call HookUncaughtExceptions +// They return the old exception handler, if there was any. Function SetOnUnCaughtExceptionHandler(aValue : TUncaughtPascalExceptionHandler) : TUncaughtPascalExceptionHandler; Function SetOnUnCaughtExceptionHandler(aValue : TUncaughtJSExceptionHandler) : TUncaughtJSExceptionHandler; // Hook the rtl handler for uncaught exceptions. If any exception handlers were set, they will be called. -// If none was set, the exceptions will be displayed using ShowException. +// If none were set, the exceptions will be displayed using ShowException. Procedure HookUncaughtExceptions; function GetEnvironmentVariable(Const EnvVar: String): String;