Upload
grayson-herring
View
217
Download
2
Tags:
Embed Size (px)
Citation preview
AS
WE
C 20
06
Proposed Notation for Exception Handling in UML 2 Sequence Diagrams
Oddleif Halvorsen
Øystein Haugen
Apr 10, 2023 Halvorsen / Haugen
AS
WE
C 20
06
2
sd U
v:V w:W
m
What are UML 2 Sequence Diagrams?
Describe interaction sequences Emphasize the interaction
between objects Partial descriptions May be used to verify
interaction properties with respect to a specification
Send event Receive event
Asynchronous message
Apr 10, 2023 Halvorsen / Haugen
AS
WE
C 20
06
3
Why the Need for Exception Handling?
”This basic description of an object cannot be cluttered up with all of the details needed for handling the contingencies.”
- Terry Winograd (1979)
Apr 10, 2023 Halvorsen / Haugen
AS
WE
C 20
06
4
Challenges wrt. Seq. Diagrams and Exceptions
How to visually isolate exception handling from a sequence diagram without disturbing the current semantics?
Sequence diagrams are often used to describe distributed and multithreaded environments– The scope of exception handling in modern programming
languages is normally limited to one call stack Sequence diagrams describes sets of traces
– There is no call stack
Apr 10, 2023 Halvorsen / Haugen
AS
WE
C 20
06
5
Example Scene – Withdrawal of money from an ATM
Happy Day Scenario– Enter a card– Give the correct pin – Select a legal amount to withdraw– Receive the money and the card
Exceptions– Unrecognized card– Wrong pin– Selected too high amount to
withdraw– ATM is out of money– Lost connection with the bank– Unable to deliver the money– Unable to give back card– ...
sd Withdrawal
:Bank:User :ATM
Code(cid, pin)
OK
refEnterPin
Cardid(cid)
msg(”Select amount”)
Amount(selectedAmount)
Withdraw(selectedAmount)
Money(selectedAmount)
card
sd EnterPin
:User :ATM
msg(”Enter PIN”)
Digitloop(4)
Apr 10, 2023 Halvorsen / Haugen
AS
WE
C 20
06
6
Handling exceptions with current standard
sd Withdrawal
:Bank:User :ATM
Code(cid, pin)
OK
refEnterPin
Cardid(cid)
msg(”Select amount”)
Amount(selectedAmount)
Withdraw(selectedAmount)
Money(selectedAmount)
card
sd Withdrawal
:Bank:User :ATM
msg(”Select amount”)
Amount(selectedAmount)
Withdraw(selectedAmount)
Money(selectedAmount)
card
alt [ correctPin == true ]
msg(”Card taken.”)
loop
Code(cid, pin)
refEnterPin
Cardid(cid)
[ correctPin != true && attempts < 3 ]
correctPin = false; attempts = 0;
alt OK(MaxAmount)
correctPin = true
msg(”Wrong PIN”)attempts++
loop [ selectedAmount <= MaxAmount ]
msg(”Select amount”)
Amount(selectedAmount)
msg(”To high amount”)
NOK
Ensuring correct pin.
Preventing the user from withdrawing more than allowed.
No valid pin given.
Apr 10, 2023 Halvorsen / Haugen
AS
WE
C 20
06
7
Our Waysd Withdrawal
:Bank:User :ATM
Code(cid, pin)
OK
refEnterPin
Cardid(cid)
msg(”Select amount”)
Amount(selectedAmount)
Withdraw(selectedAmount)
Money(selectedAmount)
card
The normal flowsd Withdrawal
:Bank:User :ATM
Code(cid, pin)
OK(maxAmount)
refEnterPin
Cardid(cid)
msg(”Select amount”)
Amount(selectedAmount)
Withdraw(selectedAmount)
Money(selectedAmount)
card
Adding exception flow without obstructing the
normal flow
exceptionInvalidPin() [pin != cid.pin]
exceptionTooHighAmount(selectedAmount, maxAmount)[ selectedAmount > maxAmount]
Reference to a diagram that handles
the exception.
Guard that triggers the exception.
Apr 10, 2023 Halvorsen / Haugen
AS
WE
C 20
06
8
Dynamic Gate Matching
sd InvalidPin
:Bank
NOK
sd PinNotOK
:ATM:User
refEnterPin
Code(cid, pin)
sd NewCode
:Bank
Code(cid, pin)
exceptionInvalidPin() [ pin != cid.pin ]
return
exceptionNoMoreAttempts() [ OutOfAttempts ]
NOKmsg(”Wrong PIN”)
critical
Recovered from the exception.
If a gate can be matched it is combined to complete the trace
Apr 10, 2023 Halvorsen / Haugen
AS
WE
C 20
06
9
Dynamic Gate Matching (continued)
ATM
:CardReader
:CashDispenser:Keyboard
:Controller
User-Reader
User-Keyboard
ATM-bank
User-Cash
:Screen
User-Screen
Withdrawalsd EnterPinsd
PinNotOKsd
NewCodesd
InvalidPINsd
NoMoreAttemptssd
The normal flow diagrams
Exception handlingwith dynamic gate
matching
Apr 10, 2023 Halvorsen / Haugen
AS
WE
C 20
06
10
The Diagram Stack
Example stack– The user enters wrong pin
twice
– Correct pin the third time
Each frame represent a new separate layer of diagrams.
Move between frames through the use of exception and return.
sdWithdrawal
sdInvalidPin
sdPinNotOk
sdNewCode
exception
0
1
sdInvalidPin
sdPinNotOk
sdNewCode
2
exception return
return
First attempt, wrong pin.
Second attempt, wrong pin.
Third attempt, correct pin.
The trace can now continue with the
normal flow.
Apr 10, 2023 Halvorsen / Haugen
AS
WE
C 20
06
11
sd U
v:V w:W
m
n
Trace Semantics
Without exceptions: U = <!m, ?m> seq <!n, ?n> Disregarding the exception: U = a seq <q> seq b seq d Recoverable exception:
– b is a subtrace such that b contains no events on the same lifeline as that of q– c [[e]] i.e. c is a trace in the exception– Provided d is not empty, it starts with an event on the same lifeline as q– U = a seq <q> seq (b par c) seq d where a,b,c,d are (sub)traces and seq is trace
concatenation and par represents all possible merge combinations
a: events executed before
the exception
b: events enabled before the exception
<q>: trigger
d: events after the exception
Exceptione() [guard]
c: exception
Apr 10, 2023 Halvorsen / Haugen
AS
WE
C 20
06
12
Conclusion
Properties of our concepts of exception in UML Seq. Diag– Compact notation– Clear visual separation between the normal flow and the
exception handling– Underpinned by precise semantics– May describe exception handling in synchronous as well as
multithreaded and distributed scenarios