Try except in thread

Posted on 2003-02-20
Medium Priority
Last Modified: 2010-04-04
I have the followin code in a thread in a service.

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

When RaiseLastWin32Error is called the exception part is not executed instead the thread just stops ?
What am I missing here ?
Question by:bnz
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 7988849
did u try to specify what exception to catch ??

  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.
LVL 34

Expert Comment

ID: 7989215
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
  {try alternate or something YOU need to do}
  hMemFile := OpenFileMapping(Alternate, False, PChar(InMemFileName));
  if hMemFile = 0 then
    {do what ever for your Non Existant Mem Map}
    ShowMessage('BAD ERROR, will break while');


LVL 20

Accepted Solution

Madshi earned 200 total points
ID: 7989363
try..except works fine in threads, too, as long as you've SysUtils somewhere in your uses clauses...

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question