开发者

Adding Exception to the operations in Sparx Enterprise Architect

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 wan开发者_如何转开发t both to throw Exception.

Image Showing class

Adding Exception to the operations in Sparx Enterprise Architect


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜