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!
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
}
}
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 :)
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.
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? :(
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.
thank you so much,.
i will give a shot for that :)
Additional guys.,
How to catch errors inside a plugin that prevent the IDE to crash? :(
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!
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?