向 Sparx Enterprise Architect 中的操作添加异常

发布于 2024-12-07 23:45:21 字数 213 浏览 0 评论 0原文

我在 Enterprise Architect 中有一个类图。

我的一个类有一些方法,我希望我的方法抛出异常。有谁知道我该怎么做吗?

如附图所示,我的接口(HsaInterface)有两个方法,我希望两者都抛出异常。

图像显示类

在此处输入图像描述

I have a Class Diagram in Enterprise Architect .

One of the my classes has some methods and I want my methods to thrown Exception. Does any have any idea how can I do that?

As in Attached image I've interface (HsaInterface) which has two methods and I want both to throw Exception.

Image Showing class

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苦妄 2024-12-14 23:45:21

EA 对操作引发的异常的表示有点混乱,而且记录也很差。本质上,异常由操作上的单个标记值表示,在逗号分隔的列表中携带异常类的(非限定)名称。

例如,Java 类 com.sun.activation.registries.MailcapFile 中的方法 parseLine 将具有一个值为 throws 的标记>MailcapParseException,IOException。

如果您在类中创建操作,该操作不会自动获取异常标记。这是因为标签名称取决于实现语言;对于 SystemC 来说是“throw”,对于 C# 和 Java 来说是“throws”(无论如何,根据手册,我还没有验证这一点)。不过,您可以自己创建标签。

如果您对一组 Java 类进行逆向工程,异常标记将填充到模型中。这可能是了解其使用方式的最简单方法。

这种仅名称的联系显然非常薄弱。它用于代码生成,但如果更改异常类的名称,则需要手动更改标记值。 EA 在代码生成期间不会检查列出的类名是否存在或是否在范围内,它只是将名称写入方法签名中。

此外,操作上的标记值无法在图表中显示。因此,虽然您可以向操作添加异常,但您只能通过查看操作的属性来查看它们。

有趣的是,EA 的数据模型确实在 t_operation 表中包含 Throws 列(因此,EA 的 API 中的 Method 类中包含 Throws 属性)。这个好像没用过。

所以这可以归结为模型的目的。如果您要使用 EA 支持异常的语言之一生成代码,则需要手动添加 throws 标记。如果您想在图表中显示异常情况,这种方法行不通。出于这样的目的,您最好从操作到异常类绘制一个依赖关系,并将其构造为“抛出”。

为了将连接器锚定到操作,请照常从类中绘制它,然后右键单击要锚定末端附近的连接器,然后选择“链接到元素特征”。

EA's representation of exceptions thrown by an operation is a bit messy, and rather poorly documented as well. Essentially, an exception is represented by a single tagged value on the operation, carrying the (non-qualified) names of the exception classes in a comma-separated list.

For example, the method parseLine in the Java class com.sun.activation.registries.MailcapFile would have a tag throws with the value MailcapParseException,IOException.

If you create an operation in a class, that operation does not automatically get a tag for exceptions. This is because the tag name depends on the implementation language; it is "throw" for SystemC and "throws" for C# and Java (according to the manual anyway, I haven't verified this). You can create the tag yourself, however.

If you reverse-engineer a set of Java classes, the exception tags will be populated in the model. This might be the easiest way to see how it's used.

This name-only link is obviously very weak. It is used in code generation, but if you change the name of the exception class, you will need to change the tag value manually. EA does not check whether the listed class names exist or are in scope during code generation, it just writes the names into the method signature.

Furthermore, tagged values on operations cannot be displayed in diagrams. So while you can add exceptions to your operations, you can only see them by looking at the operations' properties.

Interestingly, EA's data model does include a Throws column in the t_operation table (and consequently, a Throws attribute in the Method class in EA's API). This appears to be unused.

So it boils down to the purpose of your model. If you will be generating code in one of the languages where EA supports exceptions, you'll need to add the throws tag manually. If you want to show the exceptions in diagrams, that approach doesn't work. For such a purpose, you're better off drawing a Dependency from the operation to the exception class and stereotyping it "throws".

In order to anchor a connector to an operation, draw it from the class as usual, then right-click the connector near the end you want to anchor and select Link to Element Feature.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文