glib,如何处理GError的东西
glib, how to handle GError stuffs?
我有这个功能:
static
void ReadFilesInDirectory(const std::string &target)
{
GDir *dir;
GError *error;
const gchar *filename;
gchar* pathPlusFilename;
dir = g_dir_open(target.c_str(), 0, &error);
while ((filename = g_dir_read_name(dir)))
{
pathPlusFilename = g_build_filename(target.c_str(),filename,(gchar*)NULL);
if( g_file_test(pathPlusFilename ,G_FILE_TEST_IS_REGULAR) )
{
std::cout << "(file) " << pathPlusFilename << std::endl;
}
else
{
if( g_file_test(pathPlusFilename ,G_FILE_TEST_IS_DIR) )
{
std::cout << "(directory) " << pathPlusFilename << std::endl;
chdir(filename);
ReadFilesInDirectory(pathPlusFilename);
}
}
}
if(error) g_error_free(error); // gives an error at running time
g_free(pathPlusFilename);
g_dir_close(dir);
}
有一个 GError 变量,但我不知道如何从 GError 打印一些东西,http://sourcecodebrowser.com/glib2.0/2.25.8/gerror_8h.html.仅通过来自 main 的简单调用运行该代码,
ReadFilesInDirectory("/home/user/pictures")
导致运行时出错。
GLib参考手册中的错误报告部分对此进行了解释。 基本上:
GError *error = nullptr; //!\
dir = g_dir_open(target.c_str(), 0, &error);
if( error != NULL )
{
std::cout << error->message << std::endl;
g_clear_error (&error);
}
相关文章:
- 警告处理为错误这里有什么问题
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 处理多个异常集合的C++方法
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 使用流处理接收到的数据
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 基于多个条件处理地图中的所有元素
- 如何用数字处理log(0)
- SSL上的`curl_easy_send`和`curl_asy_recv`:如何处理`CURLE_AGAIN`
- 错误处理.将系统错误代码映射到泛型
- 从文本文件中读取时钟时间和事件时间并进行处理
- 在运行时处理类型擦除的数据-如何不重新发明轮子
- 在for循环中使用auto vs decltype(vec.size())来处理字符串的向量
- 用于矢量处理的多个线程
- 对字符串进行排序时,在c++中处理sort()
- 如何处理linux终端中带有负号(-)的C++中的命令行参数
- 处理除以零会导致<csignal>意外行为
- 是否可以在c++中处理字符串流中的各个元素
- glib,如何处理GError的东西