Jump to content
alogrep

Therad erro: with noerror displayed.

Recommended Posts

Hi.

Doe anyone have experienced this erro?

It just says Thread creation error:

with NOTHING shown after the 2 dots. 

Mayvbe is a ghost error?

Thi is my code 

 if lastError=0 then  begin
  prognum:=prognum+1;
try
  TTCPEchoThrd.create(ClientSock,prognum);
except
  on E:SysUtils.Exception do begin
   showmessage('prognum ='+inttostr(prognum)+' '+E.message);
  end;
end;

 

Share this post


Link to post
Posted (edited)

Why a ghost?

TThread.Create() can raise an exception using resourcestring SThreadCreateError = 'Thread creation error: %s'

And SysErrorMessage() return an empty string.

Edited by Cristian Peța

Share this post


Link to post

Thanks Christian. So to know what is the error what should I do,  what should I have in

EXCEOT

ON E: ???

Share this post


Link to post
2 hours ago, alogrep said:

Thanks Christian. So to know what is the error what should I do,  what should I have in

EXCEOT

ON E: ???

It doesn't matter what you put in the 'except' handler, the information you are looking for has already been lost before the code gets that far.  If the error text is not already present in the raised Exception then there is no text to be retrieved.  What you should be focusing on is why the error text is not present in the Exception to begin with.  That would imply a bug in SysErrorMessage(), which the RTL calls when raising an EThread exception.  If the thread failed to create than GetLastError() should not be returning an error code that has no error text associated with it (however, after an exception is raised, GetLastError() is not guaranteed to be meaningful anymore).  So, I would suggest debugging the RTL source code when the thread failure happens and see what is really going on behind the scenes.  You should not be getting a blank error message.

Share this post


Link to post

Seems suspicious to have what looks like a second create thread call with the same ClientSock but an increased prognum. 

 

In a case like this I would usually log or inspect before each call the parameters for the failing call to see if they make sense over multiple calls. 

Would also take a look at TTCPEchoThrd .create() to see what it does with the parameters being passed. 

Share this post


Link to post

HI. prognum  did nothing exept being used to give a name to a Tnxdatabae created in the execute code; I do not need it. I will eliminate;

 

Share this post


Link to post

Thanks Remy Lebeau.

What do you mean by "debugging the RTL source code"? My own code  here?

try
              TTCPEchoThrd.create(ClientSock);
except
 on E:SysUtils.Exception do begin
   showmessage('Thread creation error:  '+E.message);
 end;
end;

Or does that mean the RTL Dephi code? If so, how can I find  where the thread failure happens? 

Share this post


Link to post
21 hours ago, alogrep said:

What do you mean by "debugging the RTL source code"?

I meant exactly what I said.  You can turn on Debug DCUs in the project options, and then step through the RTL source code at runtime using the IDE's debugger.

21 hours ago, alogrep said:

My own code  here?

No.

21 hours ago, alogrep said:

Or does that mean the RTL Dephi code?

Yes.

21 hours ago, alogrep said:

If so, how can I find  where the thread failure happens? 

There is only one place it fails - in the TThread.Create  constructor.  But at least you will be able to see the actual error code before the exception is raised (provided you can reproduce the problem at will), eg:

constructor TThread.Create(CreateSuspended: Boolean; ReservedStackSize: NativeUInt);
begin
  ...
    if FHandle = 0 then
      raise EThread.CreateResFmt(@SThreadCreateError, [SysErrorMessage(GetLastError)]); // <-- WHAT VALUE DOES GETLASTERROR RETURN HERE???
  ...
end;

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×