Computer scienceProgramming languagesKotlinAdvanced featuresDSL

Require, check, and assert

Checking the price

Report a typo

We have a function that calculates the taxes of a purchase: fun getTaxes(amount: Double): Double, but we want to make sure that the cost is greater than zero; if it is not, we will throw an exception with the message: "Amount must be greater than zero".

What function should we use to perform this check in our code?

Enter a short text

Create a free account to access the full topic