Developer forums (C::B DEVELOPMENT STRICTLY!) > Plugins development

Plugin Error Catching (DB Connection)

(1/2) > >>

threeS:
Good day to all!

I have these line in my developed plugin for codeblocks IDE, the connection for my postgresql database.

--- Quote ---< . . . codes . . . >
     conn = PQconnectdb("dbname=dbname user=postgres password=postgres host=127.0.0.1 port=5432");
< . . . codes . . . >

--- End quote ---

I want to create a somewhat catch C++ code that catch if the connection fail and pops-up the fail error and not close the IDE or not crash it.

Can anybody help me please?  :(
God Bless and Merry Christmas to All!

ollydbg:

--- Quote from: threeS on December 14, 2014, 04:21:00 pm ---I want to create a somewhat catch C++ code that catch if the connection fail and pops-up the fail error and not close the IDE or not crash it.

--- End quote ---
You can simply use C++ try catch statement in your plugin source.

--- Code: ---your_plugin_event_handler_function()
{
  try
  {
    connect to your database
  }
  catch (error)
  {
    show a message box
  }
}

--- End code ---

threeS:
Thank you for that,.
Yes i can create like,

--- Quote ---catch (error)
  {
    show a message box
  }
}

--- End quote ---
because id tried something like this

--- Quote ---if(PQstatus(conn) != CONNECTION_OK) {
        Manager::Get()->GetLogManager()->Log(_("Database connection failed!"));
}

--- End quote ---
it print the error in the IDE console and crash the IDE with an error something like "Aborted (core dumped)".

I want in my "show a message box" a pop-up like error message and will not crash my IDE.,

Is that possible guys?  :(
please help me :)

oBFusCATed:
For sure it is possible.
You have to read the documentation for the API you're trying to use. Learn how to detect and handle errors, change your code.
If there are crashes use a debugger to try to understand why.

Most of the times it is dereferencing null/invalid pointers.

p.s. This has nothing to do with C::B, it is just a generic programming problem.

threeS:
Yeah, i got you point sir.
I can handle the error catching, but what i'm asking is how to display the error like a pop-up on codeblocks IDE.
So, maybe a plugin warning pop-up related something?  :(

Navigation

[0] Message Index

[#] Next page

Go to full version