Solved

Try/Except to suppress MsgBox from EInOutError

Posted on 2002-05-02
8
681 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
 

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now