Solved

Try/Except to suppress MsgBox from EInOutError

Posted on 2002-05-02
8
688 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
[X]
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
  • 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
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!

 

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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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