SWIG和例外:避免在C++中使用throw(Exception)
SWIG & exceptions: avoid using throw(Exception) in C++
我正在使用SWIG将c++库包装成JAVA库,下面的想法来自通过SWIG处理JAVA中的c++异常。
我已经能够包装我所有的异常,但是如果一个函数启动一个异常没有明确地告诉在c++声明中,JAVA代码不工作。例子:如果我做
class A {
public:
void f () throw (MyException){};
一切顺利。但是,如果我这样做
class A {
public:
void f (){};
当我在JAVA中使用代理类
捕获异常时try {
// this is the proxy wrapped (java) class
A.f();
}
catch(MyException e)
{
...
}
JAVA编译失败,出现以下错误
exception MyExceptionn is never thrown in body of corresponding try statement
我不想在我的c++代码中使用异常通知,如果我可以避免http://www.gotw.ca/publications/mill22.htm。问题是,我能避免吗?如何?
让MyExtension扩展RuntimeException而不是Exception,那么它就可以从任何函数中抛出,而不仅仅是从显式声明了抛出子句的函数中抛出。
static class MyException extends RuntimeException {
}
…
static void f() {
throw new MyException();
}
…
try {
f();
} catch(MyException e) {
}
相关文章:
- "throw expression code" 1e7 >返回 d 是什么?投掷标准::overflow_error( "too big" ) : d;意味 着?
- 为重写std::exception的库生成swig接口时出错
- 什么是 std::exception::what() 以及为什么要使用它?
- 链表"exception thrown"
- 为什么程序员同时使用 std::bad_alloc 和 std::exception.是否 std::例外 仅是不够的
- `throw 1` in C++
- C++ broken_promise exception
- gnuradio c++ connect self() throw bad_weak_ptr
- 请参阅在 Visual Studio 2019 中捕获 std::exception 时对函数模板实例化消息的引用
- QVTKWidget SetRenderWindow() with PCLVisualizer Exception
- 自定义派生的 std::exception 类的 'what' 函数返回神秘的废话
- 使用flag、return、exception、goto或break中止过程
- 为什么 c++ 使用 throw() 关键字来指示函数不会引发任何异常
- 由于某种原因,我的代码中出现了 [json.exception.type_error.302]。我知道错误意味着什么,但我不知道哪里有故障
- Poco::Net::HTTPClientSession throw exception without unique_
- 在平行区域内使用"throw exception"可以吗?
- SWIG和例外:避免在C++中使用throw(Exception)
- c++ Inline Function throw Exception: Run-Time Check Failure
- std::runtime_error::runtime_error(const std::string&) 如何满足 std::exception 对 throw() 的要求?
- 与c++的Exception throw语句混淆