HELP Exception handling doesn't work 
Author Message
 HELP Exception handling doesn't work

Hi folks,

I am currently developing a client/Server database application using
Delphi3 Client/Server suite and Interbase as the Database server.

During the programming stages I tried to program an exception handling
routing which would give a message to the user when he/she enters a wrong
userId or Password for the database.  After a few days of trying, I
couldn't get it working, so I thought there was something wrong with my
programming knowledge :-) and I thought I could solve it later.

Now I also had to write a little function which could check if a certain
String is a correct Date, so I programmed the folowing :

Function IsDate (Datum : String) : Boolean;
begin
     Try
          Result := True;
          StrToDate(Datum);
     Except
          On EConvertError Do
          begin
               ShowMessage ('Not a valid date format ! ! !');
               Result := False;
          end;
     End;
end;

For as far as I know, I don't see anything wrong with this (if something is
wrong, let me know).  But now again, the program doesn't accept the
exception handling part.  In a certain DBEdit box I have put a call to this
function (in the onexit method) and it goes something like this :

     if IsDate(EditBestel_Datum.text) <> true then
     Begin
          ShowMessage ('De ingevoerde tekst is geen datum !');  {The text
isn't a date)
          EditBestel_Datum.Text := '';
          EditBestel_Datum.Setfocus;
     End;    

This should be ok, and the function should normally handle the exeption
when the entered text isn't a date, but again everything fails.  When the
parameter Datum, which is passed to the function, contains something else
than a date, the program terminates with the folowing error message :

     Project Fotek.EXE raised an exception class EConvertError with the
message 'Tekst'
     is not a valid date and time.  Process stopped, use step or run to
continue.

The program then ends.  I am almost sure (95 % in fact) that this should
work, the program shouldn't be terminated, but the Trt .....  Except block
of my function should handle the exception, but it doesn't.

Maybe some settings in my delphi 3 Client / Server Suite are wrong, but I
don't know which ones.  If anybody has a hint about that or has the same
problem, or even knows the solution, please feel free to send me an e-mail.
 All help is welcome

Thanks in advance,

--

Stefaan Lesage
Fotek nv; Belgium



Wed, 18 Jun 1902 08:00:00 GMT  
 HELP Exception handling doesn't work



Quote:
>     Project Fotek.EXE raised an exception class EConvertError with the
>message 'Tekst'
>     is not a valid date and time.  Process stopped, use step or run to
>continue.

>The program then ends.  I am almost sure (95 % in fact) that this should
>work, the program shouldn't be terminated, but the Trt .....  Except block
>of my function should handle the exception, but it doesn't.

Under Tools | Environment, turn off Break on Exception.  This is for
debugging purposes, and invokes the de{*filter*} even when the exception
is trapped.  If you run the program outsite of the IDE, it will not
break.

Chuck Gadd
Director of Software Development, {*filter*} FX Communications.

Remove the -NOSPAM from my email address to send me e-mail.
*** I boycott businesses that send me unsolicited email adverti{*filter*}ts ***



Wed, 18 Jun 1902 08:00:00 GMT  
 HELP Exception handling doesn't work

Something you may or may not be aware of is that if you want the procedure
or function which called that function you made to handle the error, you
must include the keyword RAISE into the body of the TRY...EXCEPT ON
statement.  This passes the exception handling to the calling proc.



Quote:
> Hi folks,

> I am currently developing a client/Server database application using
> Delphi3 Client/Server suite and Interbase as the Database server.

> During the programming stages I tried to program an exception handling
> routing which would give a message to the user when he/she enters a wrong
> userId or Password for the database.  After a few days of trying, I
> couldn't get it working, so I thought there was something wrong with my
> programming knowledge :-) and I thought I could solve it later.

> Now I also had to write a little function which could check if a certain
> String is a correct Date, so I programmed the folowing :

> Function IsDate (Datum : String) : Boolean;
> begin
>      Try
>           Result := True;
>           StrToDate(Datum);
>      Except
>           On EConvertError Do
>           begin
>                ShowMessage ('Not a valid date format ! ! !');
>                Result := False;
>           end;
>      End;
> end;

> For as far as I know, I don't see anything wrong with this (if something
is
> wrong, let me know).  But now again, the program doesn't accept the
> exception handling part.  In a certain DBEdit box I have put a call to
this
> function (in the onexit method) and it goes something like this :

>      if IsDate(EditBestel_Datum.text) <> true then
>      Begin
>           ShowMessage ('De ingevoerde tekst is geen datum !');  {The text
> isn't a date)
>           EditBestel_Datum.Text := '';
>           EditBestel_Datum.Setfocus;
>      End;    

> This should be ok, and the function should normally handle the exeption
> when the entered text isn't a date, but again everything fails.  When the
> parameter Datum, which is passed to the function, contains something else
> than a date, the program terminates with the folowing error message :

>      Project Fotek.EXE raised an exception class EConvertError with the
> message 'Tekst'
>      is not a valid date and time.  Process stopped, use step or run to
> continue.

> The program then ends.  I am almost sure (95 % in fact) that this should
> work, the program shouldn't be terminated, but the Trt .....  Except
block
> of my function should handle the exception, but it doesn't.

> Maybe some settings in my Delphi 3 Client / Server Suite are wrong, but I
> don't know which ones.  If anybody has a hint about that or has the same
> problem, or even knows the solution, please feel free to send me an
e-mail.
>  All help is welcome

> Thanks in advance,

> --

> Stefaan Lesage
> Fotek nv; Belgium




Wed, 18 Jun 1902 08:00:00 GMT  
 HELP Exception handling doesn't work

Quote:

> Hi folks,

Turn the optimizer off, rebuild and try again.
--
-----------------------------------------------------------------
Opinions and statements expressed herein are personal views only.


Wed, 18 Jun 1902 08:00:00 GMT  
 HELP Exception handling doesn't work

Chuck,

Your tip on switching on switching of the 'break on exception'
(Tools->Options in Delphi 2) works great, the program is no longer
'halted'.

Thanks by a absolute Delphi-beginner (investigating the same problem
as originator of this thread).

HOWEVER: how to intercept the default handler that comes-up with:
"'99-99-1997' is not a valid date"????
(I mean, we dutch guys want our own dutch language explanation, etc,
customize this behavior...).

I tried OnValidate event on the underlying TDateField object but it
seems to be called after the EConverError is raised someplace...

still looking for more inside answers,

Leon Kemna

Quote:



>>     Project Fotek.EXE raised an exception class EConvertError with the
>>message 'Tekst'
>>     is not a valid date and time.  Process stopped, use step or run to
>>continue.

>>The program then ends.  I am almost sure (95 % in fact) that this should
>>work, the program shouldn't be terminated, but the Trt .....  Except block
>>of my function should handle the exception, but it doesn't.
>Under Tools | Environment, turn off Break on Exception.  This is for
>debugging purposes, and invokes the de{*filter*} even when the exception
>is trapped.  If you run the program outsite of the IDE, it will not
>break.
>Chuck Gadd
>Director of Software Development, {*filter*} FX Communications.

>Remove the -NOSPAM from my email address to send me e-mail.
>*** I boycott businesses that send me unsolicited email adverti{*filter*}ts ***



Wed, 18 Jun 1902 08:00:00 GMT  
 HELP Exception handling doesn't work

Quote:

> During the programming stages I tried to program an exception handling
> routing which would give a message to the user when he/she enters a wrong
> userId or Password for the database.  After a few days of trying, I
> couldn't get it working, so I thought there was something wrong with my
> programming knowledge :-) and I thought I could solve it later.

Stefaan, Look for the dBVldEdit component. A DBEdit With Onvalidate which lets
yoy validate your data before leaving the field. No more Loosing Focus/caret
after showing amessage of some kind.
works in all Delphi versions

look at :

http://www.skzl.nl/~jvdvelde

Regards, Sjef van der Velde



Wed, 18 Jun 1902 08:00:00 GMT  
 HELP Exception handling doesn't work

Quote:

> HOWEVER: how to intercept the default handler that comes-up with:
> "'99-99-1997' is not a valid date"????
> (I mean, we dutch guys want our own dutch language explanation, etc,
> customize this behavior...).

Here's what i do:

In your dpr, reassign the application.OnException event (you can do this
in your mainform as well, but i connect to the database immediately
after this)

  Application.CreateForm(Tsmmmain_frm, smmmain_frm);
  Application.OnException := smmMain_frm.AppException;

in the smmMain unit, i have

  public
    { Public declarations }
    Function  DBError(E:eDBEngineError;B:tMsgDlgButtons):word;
    procedure AppException(Sender: TObject; E: Exception);

and define these as

  procedure Tsmmmain_frm.AppException(Sender: TObject; E: Exception);
  begin
    if E is eDBEngineError then
    begin
        DBError(e as eDBEngineError,[mbRetry, mbAbort]);
    end
    else begin
      Application.ShowException(E);
    end; {case}
  end;

   Function
tSmmmain_frm.DBError(E:eDBEngineError;B:tMsgDlgButtons):word;
   var s:string; i:integer; comma:string[2];
   begin
       if E.Errorcount>1 then
          s:='The following DB errors occurred: '
       else
          s:='A database error occurred: ';
       comma :='';
       for i:=0 to pred(E.ErrorCount) do begin
          s:=s+comma+LtoS(E.Errors[i].NativeError)+
              ': "'+E.Errors[i].Message+'"';
          comma := {', '}^M;
       end;
       Result := alert_dlg.ShowMessage(
         {Msg:}      s,
         {AType:}    mtWarning,
         {AButtons:} B,
         {HelpCtx:}  0);

     {do something with result}

   end;

alert_dlg is just a form with a function showmessage defined that
displays the message and enables a few buttons. The button clicked is
returned to the caller;

If you want to translate all exceptions that the program handles,
*don't* call
      Application.ShowException(E);
but code your own that tests for each exception type, and displays a
message. The point is that many delphi units will raise the exception
with an english language text, so you'll need to test for each one.

Hope this helps

David Noakes

+----------------------------------------------------------+
|  David Noakes            _______                         |
|  Senior Consultant         | |  |          _|_      _    |

|                            |/   | | \_  | | \_ \_  \_    |
|  Phone +61 7 3371 6611     THENTEC PTY. LIMITED          |
|  Fax   +61 7 3371 6633     http:\\www.thentec.com.au     |
+----------------------------------------------------------+



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. help My crt unit doesn't work !!!!!!

2. TQuery's locate method doesn't work properly

3. Delphi+ODBC+BDE+SqlServer doesn't work

4. Why Doesn't This Work?

5. QReport doesn't work when native connection to MS Access 97 is used

6. Table1.RecNo doesn't work

7. TDataSetAction - doesn't work??

8. Why GetData doesn't work with TBLOBField???

9. Why doesn't this alias work?

10. BDE Probem, HAVING doesn't work

11. TReport.RecalcReport doesn't work

12. Turbo Pascal for Windows doesn't quite work w/ Win 95

 

 
Powered by phpBB® Forum Software