Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.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++ C++;禁用堆栈框架下的异常_C++ - Fatal编程技术网

C++ C++;禁用堆栈框架下的异常

C++ C++;禁用堆栈框架下的异常,c++,C++,有没有一种方法可以使异常在不丢失堆栈信息的情况下不在某个堆栈帧上传播 即 intfoo(){ 投掷3枚; } 整型条(){ //在这里做点什么 foo(); } int main(){ 试一试{ bar(); }捕获(…){ std::cout只需在函数声明和定义之后添加throw() #include <iostream> void* g_pStackTrace = NULL; int foo() throw(); int foo() throw() { g_pStac

有没有一种方法可以使异常在不丢失堆栈信息的情况下不在某个堆栈帧上传播

intfoo(){
投掷3枚;
}
整型条(){
//在这里做点什么
foo();
}
int main(){
试一试{
bar();
}捕获(…){
std::cout只需在函数声明和定义之后添加
throw()

#include <iostream>

void* g_pStackTrace = NULL;

int foo() throw();

int foo() throw() {
   g_pStackTrace = <stack_trace_function_call>;
   throw 3;
}

int bar() {
   // do something here
   foo();
   return 0;
}

int main() {
      bar();

      if (g_pStackTrace != NULL)
      {
           // Work with our stack
      }
}
#包括
void*gpstacktrace=NULL;
int foo()throw();
int foo()throw(){
gpstacktrace=;
投掷3枚;
}
整型条(){
//在这里做点什么
foo();
返回0;
}
int main(){
bar();
if(gpstacktrace!=NULL)
{
//使用我们的堆栈
}
}
这将阻止您的投掷呼叫

不同操作系统中的堆栈跟踪功能

backtrace\u符号(3)
-linux、mac osx

capturestacktrace(…)
-windows


异常机制将继续在更高的范围内搜索异常处理程序(catch)。如果不将异常处理程序放置在希望其停止的位置,我不知道如何停止该操作。您还可以使用
set\u unexpected()提供自己的未经指定的函数实现
function.@Mykola很抱歉,我不明白OP在寻找什么。您的解决方案是正确的,当您从
foo()中抛出时,它会终止应用程序
,这正是他想要的。@Praetorian:程序运行良好,没有任何意外情况。我尝试了这个方法,它将堆栈展开-我想保留这些信息。@Nathaniel Flath:我已经添加了更多信息来处理这个问题。
#include <iostream>

void* g_pStackTrace = NULL;

int foo() throw();

int foo() throw() {
   g_pStackTrace = <stack_trace_function_call>;
   throw 3;
}

int bar() {
   // do something here
   foo();
   return 0;
}

int main() {
      bar();

      if (g_pStackTrace != NULL)
      {
           // Work with our stack
      }
}