【问题标题】:generated Skel method missing Exception declaration in Tao_idl在 Tao_idl 中生成的 Skel 方法缺少异常声明
【发布时间】:2013-12-01 14:41:59
【问题描述】:

我在 IDL(test.idl) 文件中有一种方法:

bool login(in string name, in string cipher) raises (AuthenticationException);

AuthenticationException 在我的 IDL 文件中被声明为异常。然后我使用 tao_idl 生成具有以下参数的骨架:

-Wb,stub_export_macro=BASE_STUB_Export -Wb,stub_export_include=base_stub_export.h -Wb,skel_export_macro=BASE_SKEL_Export -Wb,skel_export_include=base_skel_export.h -GC

但是在testS.h中生成的登录方法是这样的:

virtual ::project::UserContext * login (
  const char * name,
  const char * cipher) = 0;

和testI.h:

virtual
 ::project::UserContext * login (
  const char * name,
  const char * cipher);

这对我来说很奇怪。因为方法声明缺少 AuthenticationException 异常。我相信该方法应该是这样的: 登录(..)抛出(AuthenticationException) 其中在业务逻辑中抛出自定义异常,而不是 CORBA 标准异常,客户端存根可以捕获这些异常。

我的 tao_idl 参数有问题吗?

【问题讨论】:

    标签: exception corba idl ace tao-framework


    【解决方案1】:

    不,您的 tao_idl 参数没有任何问题,这就是 IDL 到 C++ 映射的定义方式。旧版本的 IDL 到 C++ 确实在 C++ 中使用了异常规范,但最近的没有,请参阅 OMG IDL 到 C++ 映射,您可以从 http://www.omg.org/spec/CPP 获得。

    此外,IDL 到 C++11 语言的映射不使用异常规范,这种更现代的 C++ 语言映射也可从 OMG 获得,请参阅 http://www.omg.org/spec/CPP11

    您的 IDL 方法和生成的签名不匹配,使用 IDL 到 C++11 您在 IDL 中的登录方法(具有布尔返回类型)看起来像

    virtual bool login (const std::string& name, const std::string& cipher) = 0;
    

    【讨论】:

    • 谢谢@Johnny。你是对的。不匹配是复制和粘贴错误。如果没有更多的骨架异常规范,我还能在仆人登录实现中引发自定义异常(AuthenticationException)吗?同时,仍然可以在客户端捕获异常:try{} catch(AuthenticationException){} ?
    • 是的,用户异常的引发和捕获仍然有效,为了正确执行此操作,您需要在 IDL 中指定用户异常,否则将无法正常工作
    猜你喜欢
    • 1970-01-01
    • 2020-12-02
    • 2018-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-18
    • 1970-01-01
    相关资源
    最近更新 更多