TIP: Click on subject to list as thread! ANSI
echo: delphi
to: ALL
from: BRYAN SMITH
date: 1996-12-18 22:02:00
subject: Scope of Try-Except

This question relates to the scope of Try-Except
Having had trouble with Application.Terminate sending programs into an
unbreakable loops, and seeming to have little luck in fixing this with
Application.ProcessMessages, I have adopted the following scheme to stop the
program in case of a program(mer) detected error ...
1.  Set up an Exception type for handling errors.
Type
  EHaltSayErr = Class(Exception) ; { A "fake" error for Haltsay }
2.  Provide a common routine HaltSay which is called by all program-detected
errors.  HaltSay then raises an error condition ...
Procedure HaltSay(s : string) ;
begin
  MessageDlg('Fatal Error' + #13#10#13#10+s,mtError,[mbOK],0) ;
  raise EHaltSayErr.Create('Error reported by HaltSay') ;
  ShowMessage('HaltSay error trap failed') ;
end ;
3.  Try to trap these errors as follows ...
procedure TMainForm.StartBtnClick(Sender: TObject);
begin
  try
    Form6.ShowModal ; { this launches all the rest of the program }
  except
    On EHaltSayErr do { i.e. if HaltSay has been triggered }
    begin
      ShutDown ;
    end ;
  end ;  { of try-except group }
end;
Procedure ShutDown ;
{ called indirectly by HaltSay, should recover memory. }
begin
  ShowMessage('About to Terminate.') ;
  ... Run around freeing memory, etc. , then ...
  Application.Terminate ;
end ;
The main question is this.  When Form6.ShowModal is triggered by clicking
the Start button on the main form, that basically launches all of the rest
of the program.  Am I right in thinking that all program-detectable error
points, no matter what unit they are in, will then be picked up by this one
EXCEPT in the start button's on-click handler, providing they make a call to
HaltSay ?  Is Except that powerful ?
The other question is this.  Am I doing it the hard way - is there some
easier way ?
--- PPoint 2.00
---------------
* Origin: Kingston, Canada (1:249/109.11)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.