Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2021-01

MSSQL howto catch a TMSSQLConnection Error without Messagebox?

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andreas Frieß

On my Raspi/Debian i got on a TMSSQLConnection a messagebox if the server is not reachable. The connection is not my problem, but i am not able to cach this exeption silent without poping up this messagebox.

The problem is, the messagebox pops up and want an OK or ABORT. In my code i catch the exception, set a flag and reraise

try
       if IsOk then AConnection.Connected := true;
  except
       on E : Exception do begin
         IsOk:=false;
         raise;
       end;
  end;

The calling function does this
Quote
  Result := false;
  try
    xxxxxxxx(IsOk);
    Result := true;
  except
    on E : Exception do begin
     .........

     end;
   end;

So the exception should silent catched and i can handle if a connection is ok or not.

How can i avoid the unwanted box ?

regards

Andreas

Reply by email

Michael Van Canneyt
to Andreas Frieß
Andreas Frieß wrote 25 lines
On my Raspi/Debian i got on a TMSSQLConnection a messagebox if the server is not reachable. The connection is not my problem, but i am not able to cach this exeption silent without poping up this messagebox. The problem is, the messagebox pops up and want an OK or ABORT. In my code i catch the exception, set a flag and reraise try       if IsOk then AConnection.Connected := true;  except       on E : Exception do begin         IsOk:=false;         raise;       end;  end; The calling function does this Quote   Result := false;   try     xxxxxxxx(IsOk);     Result := true;   except     on E : Exception do begin      .........

Do you also re-raise here ?

Show quoted text 8 lines
    end;   end; So the exception should silent catched and i can handle if a connection is ok or not. How can i avoid the unwanted box ?

Normally catching the exception is enough.

Michael.

Reply by email

Andreas Frieß
to Michael Van Canneyt

Hi Michael,

no, i did not re-raise there.

I want only a silent flag. This should done by the Result:= false in the
calling function.

regards

Andreas

Michael Van Canneyt wrote 44 lines
On Wed, 27 Jan 2021, Andreas Frieß via lazarus wrote: > On my Raspi/Debian i got on a TMSSQLConnection a messagebox if the > server is not reachable. The connection is not my problem, but i am not > able to cach this exeption silent without poping up this messagebox. > > The problem is, the messagebox pops up and want an OK or ABORT. > In my code i catch the exception, set a flag and reraise > > try >       if IsOk then AConnection.Connected := true; >  except >       on E : Exception do begin >         IsOk:=false; >         raise; >       end; >  end; > > The calling function does this > Quote >   Result := false; >   try >     xxxxxxxx(IsOk); >     Result := true; >   except >     on E : Exception do begin >      ......... Do you also re-raise here ? > >     end; >   end; > > So the exception should silent catched and i can handle if a connection > is ok or not. > > How can i avoid the unwanted box ? Normally catching the exception is enough. Michael.

Reply by email

Michael Van Canneyt
to Andreas Frieß

If you don't do a re-raise, I don't understand where the dialog box comes from, since you're catching all exceptions...

Michael.

Andreas Frieß wrote 62 lines
Hi Michael, no, i did not re-raise there. I want only a silent flag. This should done by the Result:= false in the calling function. regards Andreas Am 27.01.2021 um 12:46 schrieb Michael Van Canneyt: > > > On Wed, 27 Jan 2021, Andreas Frieß via lazarus wrote: > >> On my Raspi/Debian i got on a TMSSQLConnection a messagebox if the >> server is not reachable. The connection is not my problem, but i am not >> able to cach this exeption silent without poping up this messagebox. >> >> The problem is, the messagebox pops up and want an OK or ABORT. >> In my code i catch the exception, set a flag and reraise >> >> try >>       if IsOk then AConnection.Connected := true; >>  except >>       on E : Exception do begin >>         IsOk:=false; >>         raise; >>       end; >>  end; >> >> The calling function does this >> Quote >>   Result := false; >>   try >>     xxxxxxxx(IsOk); >>     Result := true; >>   except >>     on E : Exception do begin >>      ......... > > Do you also re-raise here ? > >> >>     end; >>   end; >> >> So the exception should silent catched and i can handle if a connection >> is ok or not. >> >> How can i avoid the unwanted box ? > > Normally catching the exception is enough. > > Michael. -- _______________________________________________ lazarus mailing list https://lists.lazarus-ide.org/listinfo/lazarus

Reply by email

Andreas Frieß
to Mattias Gaertner

No, befor the try is  a ping to test if the server itself is reachable. This is done with a 'ShowOnTop' Form - but not showmodal. It looks like

isOk := pingtheserver(xxxx);  // <-- here is a form with showontop
created and destoyed
if isOk then begin
   try
      xxxxxxxx(IsOk);
   except
   end;
end;

No showmodal inside the try/except block. But i will check if i need the re-raise in the inner block.

Andreas

Mattias Gaertner wrote 15 lines
On Wed, 27 Jan 2021 16:02:40 +0100 (CET) Michael Van Canneyt via lazarus wrote: > If you don't do a re-raise, I don't understand where the dialog box > comes from, since you're catching all exceptions... Maybe try     xxxxxxxx(IsOk); except end; The xxxxxxx contains a ShowModal? Mattias

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot 2021-01-15 113833.jpg
Type: image/jpeg
Size: 25014 bytes
Desc: not available
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20210127/32f048d6/attachment-0001.jpg>

Reply by email