Exception db.Connect

How I do this ? It is not working when maindb.Connect is Nil exception …

It is in the open event of a window.

If maindb.Connect then

CreateStatusLabel.text = ("Banco de Dados PRINCIPAL conectado.")

else

CreateStatusLabel.text = ("Banco de Dados PRINCIPAL NO conectado. Crie ou conecte.")

end if

Exception err as NilObjectException

CreateStatusLabel.text = (“Banco de Dados PRINCIPAL NO conectado. Crie ou conecte.”)

mainDB is an Object
If you have not created an instance using NEW then it is Nil

I would suggest reading the various user guides & possibly the tutorials specifically chapter 4 of the User Guide - frameworks book available for free from http://www.xojo.com/download/extras.php

Norman, thank you. I think I missed something: I want to catch this Nil with the exception block. But it is not working. I do not know why.

If your application never creates one the exception will always be raised

I would not use a catchall exception like that
Maybe something like

[code]try
If maindb.Connect then
CreateStatusLabel.text = (“Banco de Dados PRINCIPAL conectado.”)
else
CreateStatusLabel.text = (“Banco de Dados PRINCIPAL NO conectado. Crie ou conecte.”)
end if

catch err as NilObjectException
CreateStatusLabel.text = (“Banco de Dados PRINCIPAL NO conectado. Crie ou conecte.”)
end try
[/code]

Worked. But I can not make it work when debugging. Compiled version works just fine. That’s normal ?

I did this … not sure if the pragma is the right place… but it is working now in the debugg.

#pragma BreakOnExceptions Off

Try
If maindb.Connect then

  CreateStatusLabel.text = ("Banco de Dados PRINCIPAL conectado.")
  
else
  
  CreateStatusLabel.text = ("Banco de Dados PRINCIPAL NO conectado. Crie ou conecte.")
  
end if

Catch err as NilObjectException

CreateStatusLabel.text = ("Banco de Dados PRINCIPAL NO conectado. Crie ou conecte.")

end try

In debug mode the application will stop on the exception BUT you can just hit resume
I find it a useful way to make sure that my application ha handled the exceptions that I know are going to be raised

Thank you Norman.

Set db.MultiThread = False