Jump to content

Catch exceptions from thread in UniApplication


elGringo

Recommended Posts

Hi, in vcl doing like this...

TTestThread = class(TThread)
  private
    fEx : Exception;
    procedure QueryError;
  protected
    procedure Execute; override;
  end;
procedure TTestThread .Execute;
begin
  inherited;
 
  try
    // my code
  except
    fEx := ExceptObject as Exception;
    Synchronize( QueryError );
  end;
end;
procedure TTestThread .QueryError;
begin
  Application.OnException( Self, fEx );
end;

How to do the same in UniGUI?

Link to comment
Share on other sites

tried this but didn't help

procedure THTTPThread.Execute;
var
  r,a,b: double;

begin
  { Place thread code here }
  //http request
  try
    if Assigned(FHTTPRequestFunction) then
      FHTTPRequestFunction();
    b:=0;
    a:=1;
    r := a / 0; // raises exception here but dont switch to exception block...
//    raise Exception.Create('Error Message');
  except
    on E: Exception do
    begin
      Synchronize(
        procedure
        begin
          UniApplication.UniSession.ShowAlert('Произошла ошибка ' + E.Message + #13#10 + 'Попробуйте ещё раз');
        end)
    end;
  end;

end;

Link to comment
Share on other sites

also tried this but also didn't help...

      Synchronize(
        procedure
        begin
        if Assigned(FSomeObject) then (FSomeObject as TTestFrame).showException(E.Message);
         //  UniApplication.UniSession.ShowAlert('Произошла ошибка ' + E.Message + #13#10 + 'Попробуйте ещё раз');
        end)
Link to comment
Share on other sites

tried through procedure of object, also failed...

 TExceptionNotify = procedure(AMsg: string) of object;
procedure THTTPThread.Execute;
var
  r, a, b: double;
begin
  { Place thread code here }
  //http request
  try
    if Assigned(HTTPRequestFunction) then
      HTTPRequestFunction();
    b := 0;
    a := 1;
    r := a / 0;
//    raise Exception.Create('Error Message');
  except
    on E: Exception do
    begin
      Synchronize(
        procedure
        begin
          if Assigned(FExceptionNotify) then
            FExceptionNotify('123');
        end)
    end;
  end;

end;

starting to think that unigui deny such messages from threads... to main thread....

Link to comment
Share on other sites

so guys, if you have ideas, please share, wanna try working one if somebody knows what's up...

all i want to send request in thread, because requests take 3-10 seconds and sometimes the fall to socket error or bad request - so i want to inform my user what's up, i don't want my user to wait this time

Link to comment
Share on other sites

i don't say to not use display the problem to user.

 

I think that your problem is not to catch the exception. You could verify this with using a log file and not display for test. i think you would be have lines with exception in log file with this method.

i think that the problem is to synchronize server side with client side for display the error message.

 

 

maybe it is better to use callbacks here rather than threads?

Maybe ?

 

maybe threadTimer exemple could help you ?

Link to comment
Share on other sites

so you see sessions don't give message from one thread to another (

so i put antifreeze component and handled on beginWork event and onEndWork with moving progressBar, but!

it begin working in GUI right after idHTTP processed the request

 

i fill myself on the moon, seems to be Delphi but not Delphi, pseudo Delphi in some places )))

Link to comment
Share on other sites

  • 2 weeks later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...