我有一些我正在使用的C代码,我在代码运行时发现错误,但是关于如何正确执行try/catch(如C#或C++)的信息很少.
例如在C++中,我只是这样做:
try{
//some stuff
}
catch(...)
{
//handle error
}
Run Code Online (Sandbox Code Playgroud)
但在ANSI C中,我有点迷失.我尝试了一些在线搜索,但是我没有看到关于如何实现这一点的足够信息/想象我会问这里以防万一有人能指出我正确的方向.
这是我正在使用的代码(相当简单,递归的方法),并希望用try/catch(或等效的错误处理结构)进行包装.
但是我的主要问题是如何在ANSI C中执行try/catch ...实现/示例不必是递归的.
void getInfo( int offset, myfile::MyItem * item )
{
ll::String myOtherInfo = item->getOtherInfo();
if( myOtherInfo.isNull() )
myOtherInfo = "";
ll::String getOne = "";
myfile::Abc * abc = item->getOrig();
if( abc != NULL )
{
getOne = abc->getOne();
}
for( int i = 0 ; i < offset ; i++ )
{
printf("found: %d", i);
}
if( abc != NULL )
abc->release();
int childCount …
Run Code Online (Sandbox Code Playgroud)