Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-08

Exception with threads

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

faber
Hi,
I've problems with threads. (Win32).
As example, that code is executed in thread:
    try
    spTr.LoadFromStream(ms_from_zip);
    except
       on EOutOfMemory do begin
           Result:=12;
           exit;
       end;
    end;
but in that case thread mysteriously stops working.
When I use that code:
    try
    spTr.LoadFromStream(ms_from_zip);
    except
           Result:=12;
           exit;
    end;

then everything is ok.
So my question is: may I use EOutOfMemory (and other errors) in threads ?

best regards
faber

Reply by email

Bernd Kreuss
to faber
faber wrote 22 lines
Hi, I've problems with threads. (Win32). As example, that code is executed in thread: try spTr.LoadFromStream(ms_from_zip); except on EOutOfMemory do begin Result:=12; exit; end; end; but in that case thread mysteriously stops working. When I use that code: try spTr.LoadFromStream(ms_from_zip); except Result:=12; exit; end; then everything is ok.

Maybe it raises a different exception, in the first example you only catch the EOutOfMemory.

from the manual: "If none of the On handlers matches the exception object type, then the statement list after else is executed. If no such list is found, then the exception is automatically re-raised. "

This means if it is not an EOutOfMemory then it will re-raise the exception.

Reply by email

faber
to Bernd Kreuss
Show quoted text 8 lines
Maybe it raises a different exception, in the first example you only catch the EOutOfMemory. from the manual: "If none of the On handlers matches the exception object type, then the statement list after else is executed. If no such list is found, then the exception is automatically re-raised. " This means if it is not an EOutOfMemory then it will re-raise the exception.

maybe I'm not expressed clearly. Sorry for my bad english.

When I'm testing this code I don't get and I shouldn't get any error. The only the existence of EOutOfMemory cases that thread stops working.

Maybe this is because I've capture of all exceptions in my application as
Application.OnException := @MyExceptionHandler;

best regards
faber

Reply by email