IBM Support

How to visualize and model Exception handling in Sequence Diagrams

Troubleshooting


Problem

A way to see how to model Exception handling, using IBM Rational Software Architect sequence diagrams, consists of visualizing existing code that uses these constructs. An example is provided in this technote.

Resolving The Problem

In the following example, we create two Projects, one Java Project and one Modeling Project. We use the Visualization features of RSA to create a model that shows how exceptions can be modeled in Sequence Diagrams.

A. Content of the Java Project:

The Java project will contain two packages: exceptions and pack1.
The package exceptions contains a class ExA that inherits from
java.lang.Exception
.

package exceptions;


public class ExA extends Exception {
public ExA() {
super();
}
public ExA(String message) {
super(message);
}
public ExA(String message, Throwable cause) {
super(message, cause);
}
public ExA(Throwable cause) {
super(cause);
}
}

The package pack1 contains classes A and B.
The class B has a method op that throws an exception of type ExA under some conditions.
package pack1;
import exceptions.ExA;
public class B {
public void op(int i)throws ExA{
if(i>0){
throw new ExA();
}
}
public B() {
super();
}
}

The class A has a method process that invokes op and handles the exception via a try/catch block.
package pack1;
import exceptions.ExA;
public class A {
public void process(){
B myB= new B();
try{
myB.op(-9);
}
catch(ExA e){
e.printStackTrace();
}
}
public A() {
super();
}
}

If you right click on the method process and choose:
Visualize->Add to New Diagram File->Static Sequence Diagram, you will obtain a diagram that looks like the following:



The above diagram is of type topic diagram (it has a .tpx extension).

Note for the users of Rational Application Developer

Rational Application Developer does not contain the Modeling Perspective, and does not allow you to create a model file (file with .emx extension).
Therefore, only Part A of this technote applies to the product Rational Application Developer.
However, in Rational Application Developer you can visualize the contents of a Java method, as described above. If the Visualize menu entry is not visible when you right click on a Java method in the Project Explorer, then you should go to: Windows->Preferences->Capabilities and enable the Modeling capability.


B. Contents of the Modeling Project

The easiest way to create a diagram like the above inside a UML Model is to :
  1. Go to the Model Explorer view of the Modeling perspective
  2. Drag and drop the packages exceptions and pack1 from the Java Project into an open UML Model contained in a separate UML Project or directly in the Java project.

(multi selection is possible)

This way all the Packages, Classes, Operations, Interactions etc. are automatically harvested for you in the UML Model. The results, based on the above code, is like the following:



In the above picture you can see that a Collaboration called process was added at the same level as the Operation process. This is because the topic diagram had been created before (without the Static Sequence Diagram visualization, the collaboration and interaction instead would not have been created).
What you need to do at this point, is simply add a new Sequence Diagram to the Interaction (Diagram1 in the picture above). This newly added Sequence Diagram will be automatically populated from the data contained in the Interaction.

C. Modeling of the try/catch statement:

As you can see by inspecting the model, an Alt Combined Fragment was used to model the try/catch block.

The Guard Conditions on the different Alternative Fragments are used to indicate the try block or which exception is thrown.

The ALT fragment is decorated by the keyword disruptable. You can see it by selecting the fragment and looking at Properties->Stereotype->Keywords.

The particular keyword disruptable is described in the referenced URL.



[{"Product":{"code":"SSYK2S","label":"Rational Software Architect Designer"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Modeling","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"6.0;6.0.0.1;6.0.1;6.0.1.1;6.0.1.2;7.0;7.0.0.1;7.0.0.10;7.0.0.2;7.0.0.3;7.0.0.4;7.0.0.5;7.0.0.6;7.0.0.7;7.0.0.8;7.0.0.9","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}},{"Product":{"code":"SSRTLW","label":"Rational Application Developer for WebSphere Software"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Modeling","Platform":[{"code":"PF033","label":"Windows"},{"code":"PF016","label":"Linux"}],"Version":"6.0;6.0.0.1;6.0.1;6.0.1.1;6.0.1.2;7.0;7.0.0.1;7.0.0.10;7.0.0.2;7.0.0.3;7.0.0.4;7.0.0.5;7.0.0.6;7.0.0.7;7.0.0.8;7.0.0.9;7.5;7.5.1;7.5.2;7.5.3;7.5.4;7.5.5","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}},{"Product":{"code":"SSCLKU","label":"Rational Software Modeler"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Modeling","Platform":[{"code":"PF033","label":"Windows"},{"code":"PF016","label":"Linux"}],"Version":"6.0;6.0.0.1;6.0.1;6.0.1.1;6.0.1.2;7.0;7.0.0.1;7.0.0.2;7.0.0.3;7.0.0.4;7.0.5;7.0.5.1;7.0.5.2;7.0.5.3;7.5;7.5.1;7.5.2;7.5.3;7.5.4;7.5.5","Edition":"","Line of Business":{"code":"LOB36","label":"IBM Automation"}},{"Product":{"code":"SS4JCV","label":"Rational Software Architect for WebSphere Software"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Modeling","Platform":[{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"}],"Version":"7.5;7.5.1;7.5.2;7.5.3;7.5.4;7.5.5","Edition":"","Line of Business":{"code":"LOB15","label":"Integration"}},{"Product":{"code":"SS4JE2","label":"Rational Software Architect Standard Edition"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Modeling","Platform":[{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"}],"Version":"7.5;7.5.1;7.5.2;7.5.3;7.5.4;7.5.5","Edition":"","Line of Business":{"code":"LOB36","label":"IBM Automation"}}]

Document Information

Modified date:
10 September 2020

UID

swg21221178