Bläddra i källkod

* use reference to for exception handlers

michael 5 år sedan
förälder
incheckning
27b6f1c5a3
2 ändrade filer med 6 tillägg och 5 borttagningar
  1. 2 2
      demo/errorhandler/errordemo.lpr
  2. 4 3
      packages/rtl/sysutils.pas

+ 2 - 2
demo/errorhandler/errordemo.lpr

@@ -65,7 +65,7 @@ Procedure TErrorApp.Run;
 
 
 begin
 begin
   // This will only work for the main program if you have set showUncaughtExceptions before rtl.run();
   // 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)
   // These will not be caught (yet)
   TJSHtmlButtonElement(Document.getElementById('btn')).OnClick:=@DoRaise;
   TJSHtmlButtonElement(Document.getElementById('btn')).OnClick:=@DoRaise;
   // Uncomment this to set default exception handlers
   // Uncomment this to set default exception handlers
@@ -73,7 +73,7 @@ begin
 
 
   //  Uncomment these to set special exception handlers
   //  Uncomment these to set special exception handlers
   //  SetOnUnCaughtExceptionHandler(@DoPascalException);
   //  SetOnUnCaughtExceptionHandler(@DoPascalException);
-  //  SetOnUnCaughtExceptionHandler(@DoJSException);
+    SetOnUnCaughtExceptionHandler(@DoJSException);
 
 
   // Various ways to raise an exception.
   // Various ways to raise an exception.
   // DoRaiseJS;
   // DoRaiseJS;

+ 4 - 3
packages/rtl/sysutils.pas

@@ -315,8 +315,8 @@ type
   TOnGetEnvironmentString = function(Index: Integer): String;
   TOnGetEnvironmentString = function(Index: Integer): String;
   TOnGetEnvironmentVariableCount = function: Integer;
   TOnGetEnvironmentVariableCount = function: Integer;
   TShowExceptionHandler = Procedure (Const Msg : String);
   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
 var
   OnGetEnvironmentVariable: TOnGetEnvironmentVariable;
   OnGetEnvironmentVariable: TOnGetEnvironmentVariable;
@@ -326,10 +326,11 @@ var
   OnShowException : TShowExceptionHandler = nil;
   OnShowException : TShowExceptionHandler = nil;
 
 
 // Set handlers for uncaught exceptions. These will call HookUncaughtExceptions
 // 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 : TUncaughtPascalExceptionHandler) : TUncaughtPascalExceptionHandler;
 Function SetOnUnCaughtExceptionHandler(aValue : TUncaughtJSExceptionHandler) : TUncaughtJSExceptionHandler;
 Function SetOnUnCaughtExceptionHandler(aValue : TUncaughtJSExceptionHandler) : TUncaughtJSExceptionHandler;
 // Hook the rtl handler for uncaught exceptions. If any exception handlers were set, they will be called.
 // 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;
 Procedure HookUncaughtExceptions;
 
 
 function GetEnvironmentVariable(Const EnvVar: String): String;
 function GetEnvironmentVariable(Const EnvVar: String): String;