'Exceptions in class diagrams

I need to know how to indicate in a class diagram that a method can throw an exception. I have seen that for classes it is indicated by a sterotype, but I have no idea with methods.

For example, in the following method, how would it be?

public void method () throws RuntimeException { ... }


Solution 1:[1]

According to The UML User Guide:

In the UML, abnormal occurrences are just additional kinds of events that can be modeled as signals. Error events may be attached to specification operations. Modeling exceptions is somewhat the inverse of modeling a general family of signals.

So you can model exceptions using signals, which are represented like classes but with the «signal» keyword. You can even show a hierarchy of signals. However, keep in mind that in UML, despite having many things in common with classes, signals have different semantics.

To show that a specific operation (aka "method" in Java) can throw such an exception, you can show a dependency (dashed arrow) from the operation to the signal:

enter image description here

The only drawback is that this tends to make diagrams more difficult to read if used systematically. I'd advise to use it scarcely and only if it's essential to your design and not just an implementation detail.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1