Я пытаюсь добавить FlowException в Corda Flow.
Я добавил следующую часть в мой код. Это всегда правда. Я просто хочу отобразить сообщение «Идентификатор сделки уже доступен»
val a : Int = 10
val b : Int = 10
if (a == b){
throw FlowException("Trade id already available")
}
Когда я запускаю код, поскольку потоки заканчиваются преждевременно из-за исключений, он должен отображать ошибку исключения потока. Но единственное, что он делает, это завершает поток, не отображая сообщение
Мой полный код:
object ExampleFlow {
@InitiatingFlow
@StartableByRPC
class Initiator(val iouValue: Int,
val otherParty: Party) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
// Obtain a reference to the notary we want to use.
val notary = serviceHub.networkMapCache.notaryIdentities[0]
val a : Int = 10
val b : Int = 10
if (a == b){
throw FlowException("Trade id already available")
}
val iouState = IOUState(iouValue, serviceHub.myInfo.legalIdentities.first(), otherParty)
val txCommand = Command(IOUContract.Commands.Create(), iouState.participants.map { it.owningKey })
val txBuilder = TransactionBuilder(notary)
.addOutputState(iouState, IOUContract.ID)
.addCommand(txCommand)
txBuilder.verify(serviceHub)
val partSignedTx = serviceHub.signInitialTransaction(txBuilder)
val otherPartySession = initiateFlow(otherParty)
val fullySignedTx = subFlow(CollectSignaturesFlow(partSignedTx, setOf(otherPartySession), GATHERING_SIGS.childProgressTracker()))
return subFlow(FinalityFlow(fullySignedTx, setOf(otherPartySession), FINALISING_TRANSACTION.childProgressTracker()))
}
}
@InitiatedBy(Initiator::class)
class Acceptor(val otherPartySession: FlowSession) : FlowLogic<SignedTransaction>() {
@Suspendable
override fun call(): SignedTransaction {
val signTransactionFlow = object : SignTransactionFlow(otherPartySession) {
override fun checkTransaction(stx: SignedTransaction) = requireThat {
val output = stx.tx.outputs.single().data
"This must be an IOU transaction." using (output is IOUState)
val iou = output as IOUState
"I won't accept IOUs with a value over 100." using (iou.value <= 100)
}
}
val txId = subFlow(signTransactionFlow).id
return subFlow(ReceiveFinalityFlow(otherPartySession, expectedTxId = txId))
}
}
}