【发布时间】:2014-12-06 08:02:21
【问题描述】:
作为标题,在c++中抛出异常:
class TestCpp
{
public:
TestCpp (){
NSLog(@"TestCpp init.");
throw "simple exception."; // or throw std::bad_alloc();
}
~TestCpp(){
NSLog(@"TestCpp fini.");
}
};
然后像这样捕捉它:
@try{
TestCpp o;
}
@catch(NSException* ex) {
NSLog(@"exception: %@", ex.reason);
}
@catch(...){
NSLog(@"unknown exception.");
}
但这行不通。 而且,在objc++中,如果没有办法处理C++抛出的异常,我们如何处理C++实例构造异常,比如std::bad_alloc?
【问题讨论】:
标签: c++ objective-c exception