Await and raise an error problem

Earliest possibility will be next week.

Ok ... thx .. . I'm asking because the problems which I reported are holding me with changes of my app and promoted to the production.

Hi,

After installation version 2.0.4.0 I can't understand that when I click button "Click first" the result is ok:

but when I click button "Click second" the result is bad:

Why when I raise exception 'Error Message 2' inside the

procedure TForm1.AppException(Sender: TObject; AError: TApplicationError; var Handled:Boolean);

AError.Message is "Undefined JavaScript exception" ?

For reproduce attached project:
awaitcatcherror.zip (2.2 MB)

It is because the promise rethrows the exception with an undefined exception object.
This is happening at browser level and sadly, other than catching it and passing it, there isn't much else we can do. We could block exceptions with an undefined exception object, but then you'd miss all these exception types which is also undesirable.

Ok ... not good but for me the possible option to solve the problem is add the procedure which will be run inside the try ... except like below:

procedure TForm1.AsyncErrHandling(errmessage: string);
var err:TApplicationerror;
    ehandled:Boolean;
begin
  ehandled:=True;
  err.AMessage:=errmessage;
  AppException(Self,err,ehandled);
end;

and

procedure TForm1.wbtn1Click(Sender: TObject);
begin
  try
    raise Exception.Create('Error Message 2');
  except
    on e:Exception do
      AsyncErrHandling(e.message);
  end;
end;

or do you have different idea?

I do not understand your problem.
Can't you then just ignore the application level exceptions with an undefined exception object as these come typically from the promise anyway?

Yes I can ... but after that I have exception "Undefined Java Script Exception" instead of throwing by me. In general AppException procedure is single point of error handling for my app.

For example in simply way:

[Async] procedure TForm1.Login(Sender: TObject);

begin
 
 ResponseLogin:=Await(dmDataModule.xdtwbclntClientXData.RawInvokeAsync('IWEBService.LogOn',[wbdtUserName.Text,wbdtUserPassword.Text,wbdtUserName.Text]));
              
  vToken:=String(TJSObject(ResponseLogin.Result)['value']);

  if(vToken.isEmpty)then
    raise Exception.Create('Login error');

end;

In this case I'm throwing 'Login error' but finally get 'Undefined JavaScript Exception".

The problem occurred when I changed all xdata service calls from RawInvoke to async version RawInvokeAsync.

Btw the workaround I described above may not be very elegant, but works.

I understand but again, this is a side effect of promises in JavaScript. The promise rethrows the exception from the promise code block with an undefined JavaScript exception object.

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.