3

It the exceptions thrown in case of error are represented in the UML sequence diagram, would it make the UML sequence diagram too heavy?

If they are not represented, how to tell about them?

asked Nov 19, 2019 at 23:46
4

3 Answers 3

4

Different diagrams show different perspectives, so showing them in a sequence diagram has value. It may not be sufficient to understand everything, however.

Craig Larman's Applying UML with Patterns book has an example in Chapter 35 showing exceptions as asynchronous messages (stick arrowhead). It's a pretty useful example. This figure is from the instructor's material:

Figure 35.10

answered Nov 21, 2019 at 2:55
3

The sequence diagram aims to show how objects interact in a given scenario. It is not meant to fully specify all the possible behaviors of all the involved occurrences:

  • If you would show all the possible exceptions, your diagram would be unreadable due to combinatorial explosion.
  • As qwerty_so explained, activity diagrams are better suited for that purpose.

But it could make sense in some cases to nevertheless show in a sequence diagram the scenario in case of a particular exception. For example when, due to complex interactions, it is not clear how the exception would impact the other involved occurrences in the scenario to gracefully recover.

In this case you could use a combined fragment of type break:

UML specs 2.5, section 17.6.3.9: ... represents a breaking scenario in the sense that the operand is a scenario that is performed instead of the remainder of the enclosing interaction fragment.

answered Nov 20, 2019 at 9:18
0

Rather than using SDs you should go for an AD which has Interruptible Regions to show exception handling (see bottom of https://www.uml-diagrams.org/activity-diagrams.html). It does not make much sense to (mis-)use diagrams if there are other diagram types having ways to express the things you want.

answered Nov 20, 2019 at 7:58
4
  • An advantage of sequence diagrams is to know where an exception is thrown and by which class it is caught, so that you can code it that way. I could not find an obvious example on the uml-diagrams.org link in the answer. Commented Nov 21, 2019 at 3:02
  • @Fuhrmanator The question is "Should ... be ..." and my answer is simply: No. Commented Nov 21, 2019 at 14:22
  • I found an example with activity diagrams: edn.embarcadero.com/article/30169 Commented Nov 21, 2019 at 14:34
  • @Fuhrmanator That example lacks the region itself which makes it invalid (in contrast to the example on uml-diagrams) :-/ Commented Nov 21, 2019 at 17:34

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.