I have an app in which after upgrading to 2018r3 keeps getting a NilObjectException at random times even though I have a trap on it. The exception does not crash the program and it keeps operating (a client/server app) but obviously if I click the dialog the program will quit. With the trap handled with a Try/Catch how is this exception happening and what should I look for? Any help would be appreciated.
More info required here. Your app is trying to access an object which has not been created, or was created but destroyed. You need to trace the code that relates to your object to see why it has not been instantiated, or why it was destroyed after created.
Hey. I think it has to do with the client disconnecting from the server. so If I write a response to a client that disconnects will that return a nil object? here is the code:
[code]dim sock() as TCPSocket = Window1.MainServerSocket.ActiveConnections()
Dim Looper, BailOut as integer
//find the socket handle to write to
for Looper = 0 to Ubound(sock)
if sock(Looper).IsConnected AND sock(Looper).handle = SocketID then
sock(Looper).Write TheAction
me.Sleep 150
sock(Looper).Close
exit
end
next[/code]
I am checking it with the .IsConnected but perhaps I need to trap some kind of error there?
Ok thanks Tim. I put IOExceptions on all of the server text file logging and double checked all of the objects like Dates, Nil files etc. Its trapping the NilObject but I still cannot find the problem as I cannot recreate the crash. All of these are happening in a thread and Grant mentioned “an object which has not been created, or was created but destroyed”. I am wondering if for some reason the threads are not being terminated properly. I have Return statements at the end of the thread and it in other spots so I cannot see how its not being terminated. I have been working on this problem for a week and still no luck
I usually put a nil object check in my code somewhere. You could use code like this:
[code]dim sock() as TCPSocket = Window1.MainServerSocket.ActiveConnections()
Dim Looper, BailOut as integer
//find the socket handle to write to
for Looper = 0 to Ubound(sock)
if sock(Looper) <> nil then
if sock(Looper).IsConnected AND sock(Looper).handle = SocketID then
sock(Looper).Write TheAction
me.Sleep 150
sock(Looper).Close
exit
end
end if
next[/code]
I am still getting the NilObject. I put in this in the app.UnHandledException event but the stack trace file is blank:
dim result() as string = error.Stack
Dim type As String = Introspection.GetType(error).Name
dim f as FolderItem
dim i as integer
Dim t As TextOutputStream
f=GetFolderItem("stack.txt")
If f <> Nil Then
try
t = TextOutputStream.Append(f)
t.WriteLine "Error Type: "+Type
t.WriteLine "============="
for i = 0 to result.Ubound
t.WriteLine(result(i))
next
t.Close
Catch e As IOException
//do nothing
end
End If