Just learned something again.
Method 1 below works and method 2 throws an exception.
That’s because of:
The return type is the common type between the two result values.
https://documentation.xojo.com/api/code_execution/if.html
But why is Date the common type between Date and DateTime?
Date is Deprecated.
Var d As DateTime
Var b As Boolean = False
Var dateResult As New Date
Try
// Method 1
If b = True Then
d = dateResult
Else
d = Nil
End If
// Method 2
d = If(b = True, dateResult, Nil)
Catch UnsupportedFormatException
MessageBox "error"
End Try