我需要在中间停止程序流程,而且我正在为此使用异常。这个流程是合法流程,我想知道我是否可以在不使用例外的情况下进行。在没有使用异常的情况下停止中间的程序流程
这是我的代码的例子,我不能改变func_2
和func_1
:
#include "stdio.h"
void func_3()
{
printf("i am func_3\n");
throw 20;
printf("i am not supposed to be here\n");
}
void func_2()
{
printf("i am func_2\n");
func_3();
printf("i am not supposed to be here\n");
}
void func_1()
{
printf("i am func_1\n");
func_2();
printf("i am not supposed to be here\n");
}
int main()
{
try
{
func_1();
}
catch (int e)
{
printf("i am supposed to be here\n");
}
catch (...)
{
printf("i am not supposed to be here\n");
}
}
'return;'? – JBentley
试试这个:int * i = 0; * I = 20; – Kieveli
@JBentley当你返回'func_3'时,如何让'func_2'和'func_1' **不执行它们的第二个'printf'?我想这就是OP想要的,没有例外,不需要修改'func_1/2'。 – leemes