![]() | ![]() Products ![]() ![]() ![]() ![]() |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 1 to 5 of 5 total |
![]() |
Fri, Oct 29 2021 6:22 AM | Permanent Link |
erickengelke | Good morning,
My request for today would be to change Exception handling to include the Javascript stack trace in the Exception class. It would be compatible with existing projects because it's just a new ignorable field. Debugging browser code right now can be a real pain to find the source of exception unless the programmer rewrites the internal $we() function yourself to add the stack trace. I'd also recommend a DEBUGGING flag that can turn on exception stack traces in the default handler, maybe just going to the debugging console. A horrible but effective way to accomplish that today is to just raise an exception inside the default EWB handler, then the browser will put a stack trace into the debugger output. of the true exception as well as a second message for the nasty default handler. Thanks, Erick EWB Programming Books and Component Library http://www.erickengelke.com |
Fri, Oct 29 2021 8:45 PM | Permanent Link |
erickengelke | erickengelke wrote:
> A horrible but effective way to accomplish that today is to just raise an exception inside the default EWB handler, > then the browser will put a stack trace into the debugger output. of the true exception as well as a second message > for the nasty default handler. I've been asked how to use this. So here's the code, it finds most errors anywhere in your code at runtime. procedure TForm1.myerror( o : TObject ); begin window.alert('Check the console for an error message'); raise Exception.Create('Ignore this one'); end; procedure TForm1.Form1Show(Sender: TObject); var cb : TCheckbox; err : TNotifyEvent; begin err := myerror; application.onerror := err; // next line generates an error cb.Visible := True; end; In Chrome this displays:  test.js:46545 Uncaught TypeError: Cannot read properties of undefined (reading 'tcontrol_setvisible') at main_tform1.$p.form1show (test.js:46545) at main_tform1.tcontrol_fonshow (test.js:306) at main_tform1.webctrls_tcontrol.$p.doshow (test.js:30933) at main_tform1.webforms_tformcontrol.$p.doshow (test.js:35096) at main_tform1.webctrls_tcontrol.$p.dispatchevent (test.js:30734) at webui_tdivelement.webui_telement.$p.triggerevent (test.js:21013) at webui_tdivelement.webui_telement.$p.triggercontrollerevent (test.js:21031) at webui_tdivelement.webui_telement.$p.handlechanges (test.js:19431) at webui_tdivelement.webui_telement.$p.handleupdatechanges (test.js:18762) at webui_telements.$p.endupdates (test.js:18213) And of course test.js: 46545 is exactly the line with the error, in function form1show. Very handy. Erick EWB Programming Books and Component Library http://www.erickengelke.com |
Fri, Oct 29 2021 10:22 PM | Permanent Link |
erickengelke | The following default error handling code works with most browsers: IE and Chrome and Safari, showing the line number of the error in the error message. But it only works with network based HTML/JS, not local disk versions. function TForm1.showerror( const message: String; const url: String; line: Integer; col: Integer=0; exceptionObject: Exception=nil): Boolean; begin window.alert('ERROR: '+message +' @'+IntTostr( line )); end; procedure TForm1.Form1Show(Sender: TObject); var cb : TCheckbox; begin window.onerror := showerror; // next line generates an error cb.Visible := True; end; EWB Programming Books and Component Library http://www.erickengelke.com |
Sun, Oct 31 2021 8:50 PM | Permanent Link |
erickengelke | Okay, here's the final code showing the stack trace. Tested with a bunch of browsers. This helped me find a spooky Halloween bug quickly that had eluded me for a few days.
type external TExternalException = class public property stack : string read; end; function TForm1.showerror( const message: String; const url: String; line: Integer; col: Integer=0; exceptionObject: Exception=nil): Boolean; var s : string; e : TExternalException; begin e := TExternalException( variant(exceptionObject) ); s := e.stack; showmessage('ERROR: '+message +' @'+IntTostr( line )+#13+s); end; procedure TForm1.Form1Show(Sender: TObject); var cb : TCheckbox; begin window.onerror := showerror; // next line generates an error cb.Visible := True; end; EWB Programming Books and Component Library http://www.erickengelke.com |
Mon, Nov 1 2021 12:10 AM | Permanent Link |
Richard Harding Wise Nutrition Coaching | Great - many thanks Erick.
It works really well.. Richard |
This web page was last updated on Wednesday, November 29, 2023 at 09:43 PM | Privacy Policy![]() © 2023 Elevate Software, Inc. All Rights Reserved Questions or comments ? ![]() |