c++ - 未处理的异常错误

标签 c++ unhandled-exception

我正在经历unhandled exception xutility

if (_Myproxy != 0)
    {   // proxy allocated, drain it
    _Lockit _Lock(_LOCK_DEBUG);

    for (_Iterator_base12 **_Pnext = &_Myproxy->_Myfirstiter;
        *_Pnext != 0; *_Pnext = (*_Pnext)->_Mynextiter)
        (*_Pnext)->_Myproxy = 0;  <------- unhandled exception here
    _Myproxy->_Myfirstiter = 0;
}

我无法控制xutility 。这个unhandled exception火车源于

std::string BinarySearchFile::readT(long filePointerLocation, long sizeOfData) 
{
     try{
          if(binary_search_file){
              std::string data;
              binary_search_file.seekp(filePointerLocation);
              binary_search_file.seekg(filePointerLocation);
              binary_search_file.read(reinterpret_cast<char *>(&data), sizeOfData);

              return data;  <------- branch into xutility and subsequent unhandled exception

          }else if(binary_search_file.fail()){
              throw CustomException("Attempt to read attribute error");
          }

     }
     catch(CustomException &custom_exception){  // Using custom exception class
          std::cout << custom_exception.what() << std::endl;
     }

}

通常,return将继续进行

std::string BinarySearchFile::read_data(long filePointerLocation, long sizeOfData){
    return readT(filePointerLocation, sizeOfData);
}

随后返回原始调用

attributeValue = data_file->read_data(index, size);

我做错了什么?

最佳答案

当您尝试读取数据时,data 字符串为空。这会破坏某处的内存。

您应该添加data.resize(sizeOfData)来分配空间,然后读入其缓冲区

binary_search_file.read(&data[0], sizeOfData);
                             ^^^

不进入字符串对象本身。

关于c++ - 未处理的异常错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16038954/

相关文章:

c++ - boost 日志 : How to forward a loging source

c++ - 需要一个 constexpr 来使 for 循环中的值加倍

.net - DispatcherUnhandledException 和 AppDomain.UnhandledException 何时不足(WPF 应用程序)?

c++ - 这是对逻辑 "and"运算符的正确使用吗?

c++ - C中的异构函数指针数组

c++ - 无法通过其索引从 boost::geometry::index::rtree 中删除元素

c# - Silverlight Web 应用程序未处理的异常代码 4004

wpf - 在 Microsoft 显示错误消息之前在 Word 加载项中捕获 C# WPF 未处理的异常

c# - 多种形式的异常处理

c++ - 如何检测由于磁盘已满导致的未处理异常?