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?
-
1johanvergeer.github.io/posts/…Robert Harvey– Robert Harvey11/19/2019 23:52:03Commented Nov 19, 2019 at 23:52
-
stackoverflow.com/q/26822109Robert Harvey– Robert Harvey11/19/2019 23:53:46Commented Nov 19, 2019 at 23:53
-
ibm.com/support/pages/…Robert Harvey– Robert Harvey11/19/2019 23:54:02Commented Nov 19, 2019 at 23:54
-
stackoverflow.com/a/6538299/1168342Fuhrmanator– Fuhrmanator11/21/2019 14:24:20Commented Nov 21, 2019 at 14:24
3 Answers 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:
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.
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.
-
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.Fuhrmanator– Fuhrmanator11/21/2019 03:02:53Commented Nov 21, 2019 at 3:02
-
@Fuhrmanator The question is "Should ... be ..." and my answer is simply: No.user188153– user18815311/21/2019 14:22:33Commented Nov 21, 2019 at 14:22
-
I found an example with activity diagrams: edn.embarcadero.com/article/30169Fuhrmanator– Fuhrmanator11/21/2019 14:34:33Commented 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– user18815311/21/2019 17:34:11Commented Nov 21, 2019 at 17:34