Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-04-2001, 06:05 AM
TheDuke TheDuke is offline
Senior Member
 
Join Date: Jan 2001
Posts: 269
Default help with exceptions ..... i'm getting crazy!

Looks like i can't handle exceptions in delphi4
look this simple piece of code:
procedure TForm1.Button1Click(Sender: TObject);
begin
query1.SQL.Clear;
query1.sql.Add(edit1.Text);
try
query1.Open;
except
end;
end;

it works if the query specified in the edit box is correct.
but when it's wrong the VCL handle the exceptions BEFORE my block try..except..end.

Ho do i make the VCL ignore the exception and only execute my own handler or at lease execute my handler BEFORE the VCL one?

Of course SysUtils unit is included in the uses clause.
Reply With Quote
  #2  
Old 01-04-2001, 06:32 AM
The Smurf The Smurf is offline
Member
 
Join Date: Jan 2001
Posts: 40
Default RE: help with exceptions ..... i'm getting crazy!

>Ho do i make the VCL ignore the exception and only execute my own handler or at lease execute my handler BEFORE the VCL one?

The VCL is handling the exception itself because your code doesn't handle it. You need to put your own exception handler between "except" and "end". If you don't, VCL will just handle it in the default manner.

-- The Smurf
Reply With Quote
  #3  
Old 01-04-2001, 09:10 AM
TheDuke TheDuke is offline
Senior Member
 
Join Date: Jan 2001
Posts: 269
Default RE: RE: help with exceptions ..... i'm getting crazy!

uhmm how can i handle it without notify the user?
can't i just ignore it and go on?
Reply With Quote
  #4  
Old 01-04-2001, 09:18 AM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default RE: help with exceptions ..... i'm getting crazy!

You should have no problem with the code you show.

Make sure you are not looking at the error Delphi gives when running your program through Delphi. When you run your compiled project outside of the Delphi IDE it should not show any error.

Another possibility is that it is having an error on some other code because the query was never opened due to the try except.

Can you post what the error message says?
Reply With Quote
  #5  
Old 01-04-2001, 09:36 AM
The Smurf The Smurf is offline
Member
 
Join Date: Jan 2001
Posts: 40
Default RE: RE: RE: help with exceptions ..... i'm getting crazy!

>uhmm how can i handle it without notify the user?
>can't i just ignore it and go on?

Sometimes an empty except block works (for file I/O exceptions for example), and sometimes it doesn't (for memory allocation problems, for example).

If the VCL is raising an exception, then it should be rather obvious that an empty block isn't going to work in this particular bit of code. You're going to have to be a programmer and handle it yourself.

Just because you have to handle this particular exception doesn't mean that you have to alert the user. The code you write to handle the exception doesn't have to pop up a message box or do anything obvious. But you will need to handle the specific exception in your except block if an empty block isn't doing the trick.

-- The Smurf.
Reply With Quote
  #6  
Old 01-04-2001, 09:29 PM
digitiger digitiger is offline
Senior Member
 
Join Date: Jan 2001
Posts: 716
Default RE: RE: RE: RE: help with exceptions ..... i'm getting crazy!

why dont u just add a beep or some small off screen paint
like refreshing a small label in the except block
like
try
......
....
except
beep;
or label1.refresh;
end;

in case there is no other trigger linked with query openning event (beforeopen etc) which may or may not raise some error, the above procedure will definately take care of your problem
Reply With Quote
  #7  
Old 01-04-2001, 10:08 PM
osamaao osamaao is offline
Member
 
Join Date: Jan 2001
Posts: 94
Default RE: help with exceptions ..... i'm getting crazy!

Hi :
First, Try to run your application out the IDE, because even if you handle your work with an exception, the IDE will notify you with it.

Second, some VCL related exceptions can't be handled by try ... except block, they implement the exception as an event, so you have to put you exception handler code in the event,

in your case, I think that the Query component has some events to handle the exceptions :
onEditError , onUpdateError, onPostError ...

Good luck, Osama.
Reply With Quote
  #8  
Old 01-06-2001, 01:56 PM
TheDuke TheDuke is offline
Senior Member
 
Join Date: Jan 2001
Posts: 269
Default RE: RE: help with exceptions ..... i'm getting crazy!

You were right!
the error was shown because i was running the application within the Delphi ide.
When launched outside the ide, the try..except block does its work as expected.

I didn't know about this Delphi feautre, i can figure out its utility either...
It only make the debug process much more difficult and rather boring cause anytime i have to start my application outside the ide.

Thanks a lot for your support.
Reply With Quote
  #9  
Old 01-06-2001, 06:59 PM
douglas douglas is offline
Senior Member
 
Join Date: Jul 2001
Posts: 7,695
Default How to run as if outside of Delphi IDE

How to make it run as if you were running it outside of Delphi.

Tools | Debugger Options --> Language Exceptions.

Their is a checkbox titled "Stop on Delphi Exceptions". Just make sure that is unclicked and you will not be stopped on Delphi Exceptions in the IDE anymore.

The benefit of having it show you the erorrs anyways, even though a Try Except is placed around it, is so that you can see what is really happening while you develop. If it were to show the customer an error when they run it, then it would have showed two error messages - 1 for you, 1 for what they would see.

Hope this helps you.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 10:44 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.