8

I have a question, how can I draw try catch block in sequence diagram in UML? Can I draw the try as the normal case and the catch as the alternative case or no?

I'm using Visio to dram the UML sequence diagrams.

Lisa
  • 3,121
  • 15
  • 53
  • 85

2 Answers2

6

UML sequence diagram lacks of being able to visualize exceptions. There are "workarounds" however, please refer to:

Community
  • 1
  • 1
Bela Vizer
  • 2,527
  • 22
  • 26
  • @Lisa if exceptions and alternatives are important for your model than you can use the UML activity diagram's `interrupting edge` notation together with UML sequence diagram for instance in [UML Interaction Overview Diagram](http://www.uml-diagrams.org/interaction-overview-diagrams.html) or in your customized "mix" as according to http://www.uml-diagrams.org/uml-25-diagrams.html "_..UML specification does not preclude mixing of different kinds of diagrams.._" – xmojmr Nov 09 '14 at 20:32
4

There is no standard way to model exception handling in a sequence diagram. Here is how I handle it:

enter image description here

The above diagram is generated with Web Sequence a free (open source) chrome extension. You can get it from here: https://chrome.google.com/webstore/detail/web-sequence/kcpganeflmhffnlofpdmcjklmdpbbmef or from the official site: https://www.zenuml.com . To test it out, you can simply paste the following code into the code editor of the above plugin or on the site.

JobTask.Run() {
  try() {
    Action.Execute() {
      InternalException.throw()
    }
  }
  InternalException.Catch() {
    Logger.Error()
    HighLevelException.throw()
  }
}

It demonstrates that we have a try block. Within this block, we execute Action.Execute() in which InternalException could be thrown. Then we catch it, log an error and rethrow a HighLevelException, which is a quite typical exception handling strategy.

Devs love ZenUML
  • 11,344
  • 8
  • 53
  • 67