在 PQconnectdb C++代码块中中止(核心转储)
Aborted (core dumped) in PQconnectdb C++ Codeblocks
我的代码块插件有这样的代码:
conn = PQconnectdb("dbname=codeblocks user=postgres password=postgres host=127.0.0.1 port=5432");
if(PQstatus(conn) != CONNECTION_OK) {
wxMessageBox(_("Database connection failed!" ));
PQfinish(conn);
return 0;
}
在此基础上,与数据库的连接将出错,因为它不存在,并且将显示"数据库连接失败!"消息。我的问题是,它关闭了代码块IDE并在我的终端中显示错误,如下所示:
Exception: Unknown exception was raised. The application will terminate immediately...
Aborted (core dumped)
我怎样才能在 PQconnectdb 上捕获错误,以便它不会关闭我的 IDE?顺便说一句,我在 Ubuntu 14.04 中使用C++。
首先,您可以将您起诉的代码包含在 try-catch 中:
try{
conn = PQconnectdb("dbname=codeblocks user=postgres password=postgres host=127.0.0.1 port=5432");
if(PQstatus(conn) != CONNECTION_OK) {
wxMessageBox(_("Database connection failed!" ));
PQfinish(conn);
return 0;
}
} catch (...) {
/* add breakpoint here */
}
此外,您可以检查您是否安装了多个版本的代码块。
- 数据库存在吗?
- postgresql 是否已安装?
- 您是否使用了正确的主机和/或端口?
相关文章:
- 如何找出GDB的SIGTRAP核心转储的根本原因
- C++映射分割错误(核心转储)
- 在c++中初始化矩阵时出现分段错误(核心转储)
- 在c++中键入向量中的所有值后,得到分段错误(核心转储)
- 浮点异常(核心转储)#694457
- 分段错误(核心转储)但无法弄清楚
- 链接到libkcapi时没有核心转储
- 分段错误(核心转储) - 使用 SavedModel 的 Tensorflow C++ API 进行推断
- 在基数排序中,我得到 munmap_chunk():无效指针和中止(核心转储).为什么?
- C++指针无法在函数外部传递值和分段错误(核心转储)错误
- 合并排序:分段错误核心转储
- C++:分段错误(核心转储)
- 从 pybind11 构建导入模块时出现"分段错误(核心转储)"
- 如何使用 lldb 在曼扎罗中调试 lz4 文件格式的核心转储?
- qt C++命令行代码中的分段错误(核心转储)
- 从文件中读取的数据,但发生核心转储错误
- googletest:测试基类具有纯虚拟方法的派生类时的核心转储
- C++ atof - 分段错误(核心转储)
- Linux C 只禁止我的程序使用核心转储
- 为什么我的代码包含错误分段错误(核心转储)?