Hi
I atached simple program to show the problem.
raiseerror.zip (2.2 MB)
- I set my own procedures for Application.OnError and Application.OnException like below:
procedure TForm1.WebFormCreate(Sender: TObject);
begin
Application.OnError := AppError;
Application.OnException := AppException;
end;
- The procedures are simple:
procedure TForm1.AppException(Sender: TObject; Error: Exception);
begin
console.log('From Application.OnException: '+Error.Message);
console.log('Object from Application.OnException');
console.log(Error);
end;
procedure TForm1.AppError(Sender: TObject; AError: TApplicationError; var Handled:Boolean);
begin
Handled:=True;
console.log('From Application.OnError: '+AError.AMessage);
console.log('Object from Application.OnError');
console.log(AError);
end;
- On button click I raise an exception.
procedure TForm1.wbtn1Click(Sender: TObject);
begin
raise Exception.Create('Error from raise');
end;
I don't unerstand how it works or should be.
case1:
When I raised exception I see in console:
Why message from Application.OnError is Uncaught [object Object]?
Message from Application.OnException is OK.
case2:
I commented Application.OnException:
procedure TForm1.WebFormCreate(Sender: TObject);
begin
Application.OnError := AppError;
//Application.OnException := AppException;
end;
When I raised exception I see in console:
Why did i get it again Uncaught [object Object]?
Is it bug or feature?
OnException is specific to Object Pascal code exceptions.
OnError catches everything, also underlying JavaScript related error. It doesn't do deeper checks on the error type.
then ... if OnError catches everything (Pascal and JS exceptions) why when I raise Exception.Create('Error from raise')
I get an exception object with AMessage Uncaught [object Object] but not Error from raise ?
The console.log(AError.AMessage) in procedure AppError is Uncaught [object Object] not Error from raise
procedure source below:
procedure TForm1.AppError(Sender: TObject; AError: TApplicationError; var Handled:Boolean);
begin
Handled:=True;
console.log(AError.AMessage);
end;
We'll check this with the pas2js team as this is really transpiler related.
Ok ... thank you ... I think that this is transpiler releated too, but maybe good idea will be ask pas2js team by the way additionally about await version.
For example:
procedure TForm1.wbtn3Click(Sender: TObject);
begin
await(aaa);
end;
procedure TForm1.aaa;
begin
//JS Exception
console.log(document.getElementById('aaa').id);
//Pascal raise Exception
raise Exception.Create('Error Message from await');
end;
Never mind if inside async procedure I raise error via
raise Exception.Create('Error Message from await');
or js error
console.log(document.getElementById('aaa').id);
The Application.OnError procedure and console.log(AError.AMessage) return Undefined Javascript Exception which is wrong too.
Should be for JS Exception "Cannot read properties of null (reading 'id')" and for Pascal Exception "Error Message from await"
Thank you for wanting to address this as the use Application.OnError (single point for app error handling) doesn't make sense at the moment.
Hi @brunofierens , any news from pas2js Team concerning this issue?
No conclusion/result yet.
Hi,
I see some new info in release 2.6.1.1.
It means that the problem was solved? Can you add here some detailed information?
The event object for an error raised from a promise was not properly parsed and this was fixed in v2.6.1.1
1 Like