Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么可以';我不能捕获soci::mysql\u soci\u错误异常吗?_C++_Mysql_Database_C++11_Soci - Fatal编程技术网

C++ 为什么可以';我不能捕获soci::mysql\u soci\u错误异常吗?

C++ 为什么可以';我不能捕获soci::mysql\u soci\u错误异常吗?,c++,mysql,database,c++11,soci,C++,Mysql,Database,C++11,Soci,这是我的密码 #include <soci/soci.h> #include<soci/mysql/soci-mysql.h> #include <soci/postgresql/soci-postgresql.h> #include<iostream> #include<istream> #include<ostream> #include<string> #include<exception> #

这是我的密码

#include <soci/soci.h>
#include<soci/mysql/soci-mysql.h>
#include <soci/postgresql/soci-postgresql.h>
#include<iostream>
#include<istream>
#include<ostream>
#include<string>
#include<exception>
#include<unistd.h>

using namespace std;
using namespace soci;

int main() {
    unsigned id=0;
    string name("lxc_lxc");
    int score=100;
    try {
        session sql("mysql://host=127.0.0.1 dbname=student user=root password=123");//建立连接
        transaction tr(sql);
        sql<<"insert into student1 (id, name, score) values (:item_0,:item_1, :item_2)", use(id,"item_0"),use(name,"item_1"), use(score + 1, "item_2");
        sql<<"insert into student (id, name, score) values (:item_0,:item_1, :item_2)", use(id,"item_0"),use(name,"item_1"), use(score + 2, "item_2");
        cout<<"before commit::"<<endl;
        usleep(1000000);
        tr.commit();
        cout<<"has commit"<<endl;
        sql.close();
    } catch (soci::mysql_soci_error const & e) {
        cout<<"mysql error::"<<e.what()<<endl;
    } catch (exception const & e) {
        cerr<<"Error::"<<e.what()<<endl;
    }

}
显然,它没有捕获异常。怎么了?我的makefile是这样的:

 all: main.cpp
       g++ -std=c++11 -Wall -g -o main main.cpp  -lpq -lsoci_core -lsoci_postgr    esql -lmysqlclient -ldl -lpthread -I/usr/include/mysql
   clean:

您是否使用受影响的库版本,其中基本上是从析构函数中抛出异常?我知道这有点离题,但soci有很多错误,并且没有得到很好的维护,我在运行几个小时时遇到了一些奇怪的崩溃,这似乎是由soci的连接处理不当引起的。因此,我建议切换到另一个库。
 all: main.cpp
       g++ -std=c++11 -Wall -g -o main main.cpp  -lpq -lsoci_core -lsoci_postgr    esql -lmysqlclient -ldl -lpthread -I/usr/include/mysql
   clean: