• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

Try except in thread

I have the followin code in a thread in a service.

While not terminated do
try
   hMemFile := OpenFileMapping(FILE_MAP_READ, False, PChar(InMemFileName));
   if hMemFile = 0 then
     RaiseLastWin32Error;
except
  //handle it
end;

When RaiseLastWin32Error is called the exception part is not executed instead the thread just stops ?
What am I missing here ?
0
bnz
Asked:
bnz
1 Solution
 
NightAwkCommented:
did u try to specify what exception to catch ??

except
  on Error do ...

and beside why do u call RaiseLastWin32Error ??
if an error occur OpenFileMapping will raise it itself and ur except will catch it, u dont have to raise it.

Good luck.
0
 
Slick812Commented:
hello bnz, ??????, not to sure what you are trying to do, create an exception, and then handle it???????, If you are going to Handle an exception that you create, then you may not need to create the exception????  Maybe just do something if hMemFile is Zero

While not terminated do
  hMemFile := OpenFileMapping(FILE_MAP_READ, False, PChar(InMemFileName));
  if hMemFile = 0 then
  begin
  {try alternate or something YOU need to do}
  hMemFile := OpenFileMapping(Alternate, False, PChar(InMemFileName));
  if hMemFile = 0 then
    begin
    {do what ever for your Non Existant Mem Map}
    ShowMessage('BAD ERROR, will break while');
    Break;
    end;
  end;

end;

 
0
 
MadshiCommented:
try..except works fine in threads, too, as long as you've SysUtils somewhere in your uses clauses...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now