Skip to Content
Scalus Club is now open! Join us to get an early access to new features 🎉

Control flow

Control flow is the same as in Scala 3.

The if-then-else construct is used to control the flow of the script.

The throw statement is used to throw an exception. Throwing an exception compiles to Plutus ERROR, which aborts the evaluation of the script. The exception message can be translated to a trace message using sir.toUplc(generateErrorTraces = true).

import scalus.prelude.{*, given} compile { val a = BigInt(1) // if-then-else if a == BigInt(2) then () // throwing an exception compiles to Plutus ERROR, // which aborts the evaluation of the script // the exception message can be translated to a trace message // using sir.toUplc(generateErrorTraces = true) else throw new Exception("not 2") }
Last updated on