Design – How to show the exception handler in a class diagram

designdesign-patternsuml

I have one exception handler class. I want to show this class in the uml — class diagram. But, I do not know how to represent relationship between class <X> and exception handler class. How can I represent relationship between class in class diagram?

Best Answer

From what I've seen, stereotype is usually used to represent the relationship to an exception.

a better approach would be to use UML’s stereotype notation with the keyword exception as the stereotype enclosed in guillemets, as in «exception».

Source: How can I represent an exception in UML?

This answer on Stack Overflow also suggests stereotypes, but uses <<throws>> instead. The author is confident that it's ok to use a stereotype which doesn't exist conventionally, and in this particular case, I agree with him.

As for the proper term, given that a stereotype can be a noun or a verb, both <<exception>> and <<throws>> seem equally correct. The proper terminology also depends on the language you use. For example in Python, you don't throw, but raise an error or an exception, so <<raises>> looks as the most appropriate one; unless your intention is to separate errors and exceptions, in which case <<exception>> and <<error>> may be more expressive.

Finally, Agile Modeling suggests (search for Figure 4) to embed the name of the exception like this:

+ findAllInstances(): Vector {exceptions=NetworkFailure, DatabaseError}

but IMO, while it's well suited for well-known exceptions used by the framework, it is too poor for custom exceptions you have created, because the relation is not visual enough.