How can I represent an exception in UML?

John Moore

In class diagrams, Java programmers could use a generalization relationship to show that a class extends one of the classes in the Throwable hierarchy such as Exception, but a better approach would be to use UML’s stereotype notation with the keyword exception as the stereotype enclosed in guillemets, as in «exception». This notation would also work well with languages such as C++, where there is no specific generalization hierarchy required for an exception class. If your diagramming tool supports it, you could also use color coding for exception classes or designate a special exception icon to be used for this stereotype.

Additionally, if this level of detail is desired, you could use a dependency stereotyped as «throws» to associate specific methods with the exception class, or you could use an additional exception compartment within the class rectangle which lists the exceptions associated with that class. Finally, you could use a message stereotyped as «throw» in a sequence diagram or collaboration diagram to indicate the active throwing and catching of an exception.

Note that UML treats exceptions as kind of signal, but I prefer using terminology more specific to that of exceptions.

Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact