News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Plugin Error Catching (DB Connection)

Started by threeS, December 14, 2014, 04:21:00 PM

Previous topic - Next topic

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 . . . >

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.
You can simply use C++ try catch statement in your plugin source.

your_plugin_event_handler_function()
{
  try
  {
    connect to your database
  }
  catch (error)
  {
    show a message box
  }
}
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

threeS

Thank you for that,.
Yes i can create like,
Quote
catch (error)
  {
    show a message box
  }
}
because id tried something like this
Quote
if(PQstatus(conn) != CONNECTION_OK) {
        Manager::Get()->GetLogManager()->Log(_("Database connection failed!"));
}
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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

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?  :(

oBFusCATed

Either use the cbMessageBox function, the InfoWindow class or the LogManager.
It is up to you to decide what you should do with your plugin.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

threeS

thank you so much,.
i will give a shot for that  :)

threeS

Additional guys.,
How to catch errors inside a plugin that prevent the IDE to crash?  :(

oBFusCATed

Use a debugger to find the cause, then fix the bug.

If you read the c++ specification you'll find that you cannot catch segmentation faults/access violations as exceptions!
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

threeS

that is why . :(

I have another idea, maybe i can disable the plugin, so that the IDE will not crash.
How can it be possible?