Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 05-21-2018, 09:59 PM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 310
Default SQL login and errors

I must admit I have never use try in my code before. I have always tried to write code that checks data before doing any function.

The problem and it may be my delphi understanding that is the problem.

I have a program that connects to remote or local database. What I'm finding is that if a user tries to login and for example the wifi is not connected or the local server is not running, the program crashes.

I'm trying to catch the crash and get the user to change a parameters.

I'm using Mysql and MyDac from Devart. (I've having limited success with Devart support hence I'm looking at delphi inderstanding)

Code:
procedure TfLogin.LoginClick(Sender: TObject);
begin
   dm.Regisiter.Username:= eName.Text;
   dm.Regisiter.Password:= ePassword.Text;
   try
      dm.Regisiter.connect;
   except
      on E: EMyError do
         showMessage('Not connected');
   end;
end;
when I run this I get a error message "Raise and exception in MySqlException"

Not sure how to fix this.

Any suggestions ?

Last edited by Marsheng; 05-21-2018 at 10:08 PM.
Reply With Quote
  #2  
Old 05-22-2018, 08:03 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,303
Default

EMyError is probably not the exception type that is thrown.
You could try E:Exception instead. That catches any exceptions.
Reply With Quote
  #3  
Old 05-22-2018, 09:07 AM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 310
Default

No difference. See attached.
Attached Images
File Type: jpg Error.jpg (35.2 KB, 6 views)
Reply With Quote
  #4  
Old 05-22-2018, 01:14 PM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,303
Default

Tools --> Debugger Options --> language Exceptions --> "Stop on Delphi Exceptions" --> Uncheck
Reply With Quote
  #5  
Old 05-22-2018, 09:29 PM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 310
Default

Thanks - Whoo - it works. I have emailed about 20+ emails to forums to get this answer.

Ok, I have had a brief look but not found a solution as yet. Is it possible to change this setting at run time ? I would only like this only set when trying to login. If always set, I wont catch any other errors.
Reply With Quote
  #6  
Old 05-23-2018, 09:33 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,303
Default

In the newer Delphi versions you have Exception types to ignore, where you can add specific exceptions to ignore.
But you'll have to check the "Stop on Delphi Exceptions" back again

Only thing I'm not sure of is what you should specifically add, but I'll guess it's some trial and error...
Reply With Quote
  #7  
Old 05-24-2018, 10:31 PM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 310
Default

I get "Raise and exception in MySqlException" in the IDE mode only.

If I run the exe, no error. Is this normal ?
Reply With Quote
  #8  
Old 05-25-2018, 06:49 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,303
Default

Yes, that checkbox set to "false" emulates somewhat the user experience.
It's normally the first thing I uncheck, but I guess there's a reason why it's default "true"...
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 05:23 PM.


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