mengmeng
mengmeng

Reputation: 1506

Null check groovy way result of database query

This might seem simple but it's my first time dealing with groovy and database interactions

I have to get something from the database and check if it's NOT NULL, I'll throw an Exception

PaymentDetails details = PaymentDetails.findById(id)

What is the groovy way to check if the details is NOT NULL?

Is condition seems wrong :(

if (!details) {
    println("ERROR!!!!")
    throw new InvalidException()
}

Thanks in advance!

Upvotes: 1

Views: 455

Answers (1)

Tommy
Tommy

Reputation: 366

if (details) {
    println("ERROR!!!!")
    throw new InvalidException()
}

Refer to docs on The Groovy Truth to understand how Groovy decides on boolean expressions.

Upvotes: 1

Related Questions