Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Try/Except to suppress MsgBox from EInOutError

Posted on 2002-05-02
8
Medium Priority
?
690 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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 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 brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

670 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