How can I represent try catch block with SQLException throw in UML sequence diagram?

Banik :

I'm struggling to understand how can I represent following code by UML Sequence diagram:

What I already have:

Picture of my UML sequence diagram

Java code:

public static Connection getDbConnection() throws SQLException{
if (instanceOfDbConnect == null) {
        instanceOfDbConnect = new DbConnection();
        System.out.println(" Connection  - - - - - - - -  Trying to create DBConnection.");
    }
    try {
        return DriverManager.getConnection(URL,user,password);
    } catch (SQLException e) {
        throw e;
    }

}

How can I deal with this throwing SQLException if it's done in this way? It's seems to me that I should get a return message (throw e) from SQLException to DbConnection. But what is the sender message from DbConnection to SQLException?

Thank you very much for all your help!

qwerty_so :

As commented UML is not the best when it comes to real code. Your eight lines of code (not counting the single closing bracket lines) are very clear. An attempt to draw that as SD could look like

enter image description here

Would that help in documenting? Well, it depends. You have to deal with lots of graphical elements and depending on the tool you spend a lot of time arranging arrows frames and life lines. That might turn out being a PITA. And it's even not clearer than this little code example.

Now consider this example: enter image description here

Here the behavior is stored in the notes of the messages (using Enterprise Architect). Instead one could use a note element instead and place it on the diagram.

So what ever route you go: it's all about communication. Use what ever is best to communicate the idea. SDs are great when you want to show a complex collaborations where many objects are involved. But at a certain level teh codez are just the best to transport the message.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=149023&siteId=1
Recommended