Nil Exception - Deja Vu'

This has to be the most frustrating class of exception.

I have an app with the following process

  • A Toolbar - when the user clicks an item it sets a “command” variable to a particular value (depending on which item)
  • it then calls a method with a dispatcher… “SELECT CASE” that calls a method based on then command passed in, this way commands can be executed by various means
  • in this particular case the method called does some processing, and calls a method that manages Most Recent Used Files
  • If I put a break on the CALL, it stops as expected, if I then tell the debugger to STEP, it bombs with Nil Exception
  • HOWEVER… if I put a break on the VERY FIRST line of the method being called… it STILL bombs

How can I find out what the heck is going on when the exception seems to occur between two breakpoints that should be one after the other?

FYI… everything seems to be initialized… and MRUF_Manage is actually successfully called multiple times during App Open (loading recent files from a previous session)

FUNCTION project_save(f as folderitem) // this appears in the log below
MRUF_Manage Project_Path.nativepath ///   first break point, and this is last executable statement in method
Public Sub MRUF_Manage(filename As String, delete_it As Boolean = false)
  #If Not DebugBuild
    #pragma DisableBackgroundTasks
    #pragma DisableBoundsChecking
    #pragma StackOverflowchecking False
    #pragma NilObjectChecking False
  Dim i As Integer   // <---- SECOND BREAK POINT, it bombs BEFORE it gets her
  Dim j As Integer
  Dim x As Integer
  If filename="" Then Exit Sub
  //if left(filename,9)="/volumes/" then filename=mid(filename,10(
  ' if file is already in the list .. move it to the top
  If x>=0 Then
    For i=0 To x
      If MRU_Files(i)=filename Then
        Exit For
      End If
    Next i
    If j>0 Then
      If j=0 Then Exit Sub  ' already at the top
    End If
  End If
  If Not delete_it Then 
    MRU_Files.Insert 0,filename
  End If
End Sub

is projectpath nil since the break is logically BEFORE that line has executed and Project_Path.nativepath might cause an NOE

No… project path has a valid path, as observed during the first break point

DB_DEST is an on disk SQLite database
DB_PROJECT is an in-memory database
the purpose is to copy project -> dest
it makes it to MRUF_Manage
neither database exhibit any error message

this is the code surrounding the 1st breakpoint

If DB_Dest.Connect Then 
DB_PROJECT.Backup(DB_Dest, Nil, -1)
MRUF_Manage Project_Path.nativepath
set_change False
unexpected_error("#1 in Project Save")
End If

Also “f” , “project_path” and the path to DB_DEST are all the same value

Ok… this seems to have fixed it, but I do not know why
I created an Overload of MRUF_Manage that accepts a FolderItem instead of a string
and it returns if that folderitem is nil

This works, even though in the original situation the Project_Path was NOT nil