2

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?

4

3 Answers 3

3

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

2

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.

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.

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. Nov 21, 2019 at 3:02
  • @Fuhrmanator The question is "Should ... be ..." and my answer is simply: No.
    – user188153
    Nov 21, 2019 at 14:22
  • I found an example with activity diagrams: edn.embarcadero.com/article/30169 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) :-/
    – user188153
    Nov 21, 2019 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.