mingw-gcc std::exception问题
来源:互联网 发布:汤臣倍健vb功效与作用 编辑:程序博客网 时间:2024/06/13 23:04
在MSVC中抛出异常代码如下:
#include <iostream>#include <stdexcept>#include <stdlib.h>void exception_test(){ throw std::exception("exception_test EXCEPTION");}
int main(){ try{ exception_test(); } catch(const std::exception& e) { std::cout<<e.what()<<std::endl; } catch(...){ std::cout<<"exception catch...\n"; } system("pause"); return 0;}
在main函数中可以正确的捕捉到std::exception异常,输出:
> exception_test EXCEPTION
但是在mingw-gcc,exception_tes()函数不能编译通过,
> error: no matching function for call to 'std::exception::exception(const char [25])'
这是因为使用的编译器中std::exception根本就没有std::exception(const char* )类似的构造函数;
为了让exception在msvc和mingw-gcc中都能编译通过,修改exception_test()实现;
void exception_test(){ throw "exception_test STRING"; throw std::runtime_error("exception_test RUNTIME_ERROR");}如果直接throw 字符串,main函数中输出
> exception catch...
如果 throw std::runtime_error,效果和在msvc中使用throw std::exception效果一样,
> exception_test RUNTIME_ERROR
- mingw-gcc std::exception问题
- 关于AF_INET,gcc 和 mingw问题
- MinGW GCC下sleep()函数问题
- MinGW GCC下sleep()函数问题
- MinGw 、GCC
- GCC、Cygwin、MinGW、TDM-GCC
- C++ Std exception
- GCC版本切换,-std=c++11问题
- cygwin/gcc与MinGW
- gcc/mingw/libstdc简介
- gcc/mingw/libstdc简介
- cygwin/gcc与MinGW
- 编译MinGW版GCC
- cygwin/gcc/msys/mingw
- cygwin/gcc与MinGW
- cygwin/gcc与MinGW
- cygwin/gcc与MinGW
- cygwin/gcc与MinGW
- 2012年10月国庆长假天津-内蒙古自驾游之我们在路上
- VS2005 Debug时提示没有找到MSVCR80D.dll的解决办法 .
- eclipse构建maven的web项目
- websphere6.1下项目初始化报错 .
- ubuntu下minicom的安装及使用
- mingw-gcc std::exception问题
- linux脚本----shell 的 && 和 ||
- ARM与x86之3--蝶变ARM
- HTML5 动画演示
- linux下cat的使用
- 在JSP编译的时候,服务器内部做了什么?
- 创建不可实例化的类
- MyEclipse编码设置
- 使用ajaxfileupload.js插件实现Ajax方式上传文件