![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Executing shell program from a web page | venkatritch | Shell Programming and Scripting | 5 | 06-14-2008 06:36 AM |
| after executing execvp()... program hangs up | Crab | High Level Programming | 3 | 09-21-2006 11:31 AM |
| Executing an .ec program in different informix versions | matrixmadhan | High Level Programming | 0 | 05-21-2005 07:29 AM |
| executing the su command from a java program. | shailendrat | UNIX for Dummies Questions & Answers | 1 | 03-24-2005 12:27 PM |
| executing a program within a program | Gekko | High Level Programming | 4 | 06-27-2002 04:36 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
I wrote a code like this.......
#include <iostream> #include <stdio.h> #include <mysql.h> #include <string.h> #include <stdlib.h> using namespace std; #include "Connection.h" int main() { char *Host = (char *)"localhost"; char *Database =(char *)"sachin"; char *UserId =(char *)"root"; char *Password =NULL; Result *result; char *query; Connection DbConnection(Host, Database, UserId, Password); query="select * from the test"; // test is my database result = DbConnection.Query(query); // perform the required database operation.. return 0; } Connection is the class & have connect function that just took the 4 arguments & establishes the connection to the mysql server ...Also Query is the function defined in connection class. I m getting output as - $g++ -c -I/usr/include/mysql Main.cpp $ g++ -o Main Main.o -L/usr/lib/mysql -lmysqlclient $./Main terminate called after throwing an instance of 'char const*' Aborted I don't know why i m getting this output. I think it is related to the library....... Can any one help me...... Last edited by ps_sach; 10-20-2008 at 05:45 AM.. |
|
||||
|
Either the constructor of Connection, or the Query() method throws an exception of type const char *. You can catch it, by enclosing the calls with try, and adding a catch block, like:
Code:
try {
Connection DbConnection(Host, Database, UserId, Password);
query="select * from the test"; // test is my database
result = DbConnection.Query(query); // perform the required database operation..
}
catch (const char *errmsg)
{
std::cerr << "error message from connection: " << errmsg << "\n";
return 1;
}
|
|
||||
|
Quote:
On the other hand, if the function would in fact require a "char*" it might expect the value to be writable, which is not the case for string literals. But I don't think that is the case here. Also, the meaning of the message "terminate called after throwing an instance of 'char const*'" is pretty clear. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|