silent crash of the application

Hello all; I have an issue with a web application where it crashes silently either compiled or in the IDE. I narrowed it down to retrieving one specific piece of data from the database. The content of the field is null. Here is my code. I would expect it to catch the NilObjectException:

Try Me.GroupeDate = DateTime.FromString(rs1.Column("groupedate").stringvalue,Locale.Current, TimeZone.Current) // fails here. Program exit, no error or exception. Catch e As NilObjectException Me.GroupeDate = DateTime.FromString("1899-12-31",Locale.Current, TimeZone.Current) End Try

There must be something obvious that I am overlooking, but right now I can’t figure it out.

So, here it is . Ready to be enlightened! Thanks in advance!

Edit: Xojo 2019 R3.1, developed on Windows 10 X64.
Edit 2: I tried replacing NilObjectException with RuntimeException. Same behavior.
Edit 3: the workaround is simple: define a default date in the database (1899-12-31 in this case). But I would prefer to not do that. This is a different discussion.

Looks like you’ve found a bug that should be reported.

I tested using this code

[code]Var db As New SQLiteDatabase

db.Connect

db.ExecuteSQL(“CREATE TABLE test (id INTEGER NOT NULL PRIMARY KEY, adate DATE);”)

db.ExecuteSQL(“INSERT INTO test (id) VALUES (1);”)

Var rs As RowSet = db.SelectSQL(“SELECT * FROM test;”)

Var myDate As DateTime = DateTime.FromString(rs.Column(“adate”).stringvalue,Locale.Current, TimeZone.Current)

Break[/code]

and the IDE doesn’t break where it should.

I do wonder why you aren’t using the DateTime value of the column though?

[code]Var myDate As DateTime = rs.Column(“adate”).DateTimeValue

If myDate = Nil Then
myDate = New DateTime(1899, 12, 31, 0, 0, 0, 0, TimeZone.Current)
End If[/code]

seems to be a windows only bug
both of these hit the break statement just fine in 2019r3.1 on 10.14.6 here

Var db As New SQLiteDatabase

Call db.Connect

db.ExecuteSQL("CREATE TABLE test (id INTEGER NOT NULL PRIMARY KEY, adate DATE);")

db.ExecuteSQL("INSERT INTO test (id) VALUES (1);")

Var rs As RowSet = db.SelectSQL("SELECT * FROM test;")

If False
  Dim c As DatabaseColumn = rs.Column("adate")
  
  Var myDate As DateTime = DateTime.FromString(c.stringvalue,Locale.Current, TimeZone.Current)
else
  
  Var myDate As DateTime = DateTime.FromString(rs.Column("adate").stringvalue,Locale.Current, TimeZone.Current)
End If

Break

Wayne, I am not using the construct that you suggest because I am just too lazy. :wink:

Incidently, the line where I force 1899-12-31 is not the issue. And yes I believe that this is a DateTime bug. The documentation states that DateTime should raise a RuntimeException if a string with a wrong format is provided to the FromString shared method. I would expect that a null date is a wrong format… So, I created <https://xojo.com/issue/58956>

In the mean time, I can work around the bug by testing that the string is not null before trying to create a date with it.

This reminds me to a bug couple of years ago. In my case it was the local timezone and the fact that on the server there simply was no local one (UTC) even when the underlaying System has defined one. I solved the problem in using UTC in all my my database time fields, maybe you check this first?

Thanks Thomas, I checked without timezone ans with UTC. Same behavior.

you mean this part?

if the field exists i would expect it return a empty string “”
then it looks like
=DateTime.FromString("",Locale.Current, TimeZone.Current)

This is very interesting. I made a bug report on a similar bug on the Mac side: <https://xojo.com/issue/58879> . Unfortunately, I wasn’t able to reproduce the bug yet.

My Feedback Case # 58956 was marked as verified and then later marked as fixed. Thank you @William Yu !