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
Solved

Try/Except to suppress MsgBox from EInOutError

Posted on 2002-05-02
8
686 Views
Last Modified: 2010-05-18
Delphi 5 program runs in both Batch and Interactive mode.
When run in Batch mode I wish to suppress all msgboxs so that the run is not impeded.
This can be done by sprinkling  '$I'  comments throughout the program.
It should be possible to use try/except to trap all these EInOuterror  's between try AND except.
I find that during testing if I force one of the exceptions to be thrown , say by
writing to an unopened file, that a MsgBox comes up from the system and then my
exception handler code is executed.

 Am I missing something? Can I somehow stop the system from putting up the messagebox
 In my Exception handling code I want a MsgBox only if in Interactive mode and I want
 to log and error message regardless of the run mode.
 
 Below is an outline of what I tried:
 
/////// Begin $I
{$I-}
 Writeln(gfProgLog,'PROJECT_ID!   CASEID! IwLength(minutes) '); ///!!!!!!! noit open yet
{$I+}
 if IOResult <> 0 then
       Writeln(fLog,'Handle IO error by self.');
       
ASSIGNFILE( gfProgLog, 'c:\AR_Programmer.log' ); // open single LOG file
REWRITE( gfProgLog );      
\\\\\\ END $I


////// BEGIN Exception code
       
try

-->     ENTIRE PROCEDURE HERE <---

except      {end big try}
on  E :EInOutError do
begin  
  if gbBatchMode = false then
    MessageDlg('AR:I/O error ' + E.Message + ' Line# ' + IntToStr(nLineCnt) + ' file: ' + slFileList[I], mtWarning, [mbOk], 0)
    { specific exception-handling code }
  else
  begin    
    writeln(fLog,'AR:I/O error ' + sTemp + ' Line# ' + IntToStr(nLineCnt) + ' file: ' + slFileList[I] );
  end;
end ;
on  E :EStringListError do
begin
        ......
end;
else
  begin
    if gbBatchMode = false then
      MessageDlg('AR:Unhandled non-IO/non Stringlist error :no message yet ' + ' Line# ' + IntToStr(nLineCnt) + ' file: ' + slFileList[I], mtWarning, [mbOk], 0)
    else
      writeln(fLog,'AR: unhandled non- IO error ' + sTemp + ' Line# ' + IntToStr(nLineCnt) + ' file: ' + slFileList[I] );
  end;
    { default exception-handling code };
end;  {except}


   
0
Comment
Question by:mebarron
  • 6
  • 2
8 Comments
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6986469
Can't you use a TApplicationEvents' OnException eventhandler for that?



Good luck!!
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6986477
For example:

procedure TForm1.ApplicationEvents1Exception(Sender: TObject;
  E: Exception);
begin
 if (E is EInOutError) then
 begin
   //yada
   //yada
   //yada
   //yada
 end;
end;




0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6986478
For example:

procedure TForm1.ApplicationEvents1Exception(Sender: TObject;
  E: Exception);
begin
 if (E is EInOutError) then
 begin
   //yada
   //yada
   //yada
   //yada
 end;
end;




0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:mebarron
ID: 6987345
I created
 procedure TForm1.ApplicationEvents1Exception
As you advised. Is there anyway to get the execution
to resume where the error occurred? Say the prog is
processing a series of files. It would be great to be
able to continue processing with the next file
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6988344
Hmmm... well, it seems that you're using a TStringList to keep track of the files that you're processing. If this is so, then I would imagine that you should be able to delete the file name once you're done with it. Now, in the OnException, you could simply call the routine again that processes the files. It might be necessary to delete the first item from the TStringlist first, however, since presumably that was the one that gave you an error in the first place (it wasn't processed and deleted within the processing routine).Of course the filelist  will have to be global. Psuedocode looks like this:



Routine -> Process files
OnException ->deletes the first file in the que and calls routine to continue.


Good luck!!

0
 
LVL 6

Accepted Solution

by:
DrDelphi earned 50 total points
ID: 6988346
Better PsuedoCode:

Routine:
   while Filelist.count>0
   Process file
   Delete Filename from fileList
   Continue;

OnException:
       Delete FileList[0]//get rid of the offending file
       possibly WriteToLog('FileList[0] failed')
       Call Routine;


Good luck!!

0
 

Author Comment

by:mebarron
ID: 6992010
Many Thanks Dr Delphi
I really like the idea of using index == 0
together w/ deletion of string.
I'll be back. Mark
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 7006538
Cheers.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi prevent click fast 2 238
Delphi Dbf export problem to a Visual Foxpro application 6 207
Printing problem 2 102
CheckListBox usage 3 71
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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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