nil object with MacOS 9.0.4 
Author Message
 nil object with MacOS 9.0.4

Hi,

I compiled a program which runs as well from 8.6 to 9.0.4. Now I'm
getting a mail from a user with 9.0.4 telling me that the program quits
on start up with a nil object exeption error. On start up the prefs are
created. It's difficult to track it doen, since I can't reproduced it
and the user is few thousend km away. Does anybody have had a similar
problem with rb comiled software?

thx
Andreas    



Mon, 01 Nov 2004 16:42:12 GMT  
 nil object with MacOS 9.0.4

Quote:

> Hi,

> I compiled a program which runs as well from 8.6 to 9.0.4. Now I'm
> getting a mail from a user with 9.0.4 telling me that the program quits
> on start up with a nil object exeption error.

You should do more checks for nil.

Maybe your app can't create a file so a binarystream is nil.

Mfg
Christian

--
In a world without walls and fences you don't need windows or gates.

http://www.christians-software.de (Free Mac/Win software)



Mon, 01 Nov 2004 17:19:36 GMT  
 nil object with MacOS 9.0.4

Quote:

> Does anybody have had a similar
> problem with rb comiled software?

Sure, people have this problem all the time.  Of course, at least
you're getting a polite notification of something wrong.  In most other
languages, you'd more likely simply have system crashes that happened
sporadically and in different ways each time.  It's not RB that's to
blame, it's not enough error checking in your code.

Any time you create a new Picture, FolderItem, BinaryStream,
TextOutputStream, etc, you need to check to make sure it actually got
created.  For example, the following code can easily fail in multiple
ways with these NilObjectException errors.  

  dim f as FolderItem
  dim s as BinaryStream

  f = PreferencesFolder.Child("myPrefs")
  s = f.CreateBinaryFile("application/me_prefs")

A better way of writing the above code would be:

  dim prefsFolder, prefsFile as FolderItem
  dim s as BinaryStream

  prefsFolder = PreferencesFolder
  if prefsFolder = nil or not prefsFolder.exists then
    // handle error
  else
    prefsFile = prefsFolder.Child("myPrefs")
    if prefsFile = nil then
      // handle error here
    else
      if prefsFile.exists then
        s = prefsFile.OpenAsBinaryFile(true)
      else
        s = prefsFile.CreateBinaryFile("application/me_prefs")
      end if
      if s = nil then
        // handle error here
      else
        // read from s here
      end if
    end if
  end if

Yes, it's significantly longer, but it's also significantly safer.  You
may even want to add a directory check -- make sure prefsFolder is
really a folder and prefsFile is NOT a folder.



Mon, 01 Nov 2004 21:29:53 GMT  
 nil object with MacOS 9.0.4

Quote:

>   dim f as FolderItem
>   dim s as BinaryStream

>   f = PreferencesFolder.Child("myPrefs")
>   s = f.CreateBinaryFile("application/me_prefs")

> A better way of writing the above code would be:

[Check for every possible nil snipped]

Another way would be to add an exception handler:

  dim f as FolderItem
  dim s as BinaryStream

  f = PreferencesFolder.Child("myPrefs")
  s = f.CreateBinaryFile("application/me_prefs")
  ...write to your file...

exception
   // handle (or ignore) an error

In other words, if it's not a mission-critical function and you think
it may be likely to fail, you can just catch all exceptions and ignore
them.  Not great coding practice, but better than crashing.

Cheers,
- Joe

--
,------------------------------------------------------------------.
|    Joseph J. Strout         Check out the Mac Web Directory:     |

`------------------------------------------------------------------'



Mon, 01 Nov 2004 23:32:23 GMT  
 nil object with MacOS 9.0.4

...

Quote:
> In other words, if it's not a mission-critical function and you think
> it may be likely to fail, you can just catch all exceptions and ignore
> them.  Not great coding practice, but better than crashing.

Without doubt you are right. Well I'm testing for nil and the
preferences are created. When forgot a nil test, I have to llok for it,
sure.

What I'm wondering is something slithly different, not there is any nil
object error. But the error occurs during start up before any user
action is possible (but after creating some preferences). The start
process should be equal on all systems since I didn't programmed any
special system calls. It should crash always or never. But on my system
9.0.4 it works, on the users system 9.0.4 it doesn't. The main
difference between the systems are the language (de versus en). Thst's
what I'm wondering about.

Anyhow thx to all for answers



Tue, 02 Nov 2004 22:49:28 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. VA 4.5 IIOP and nil objects

2. Nil Object Exception Problem in database

3. object = nil

4. Database nil object exception

5. ADA for MacOS 9 and MacOS X?

6. Problem: MacOS Wish and Object Command Lang.

7. function-objects and code-objects ( was: re-creating objects and security )

8. What does this mean? Error: Attempt to set the value of nil to nil.

9. (string-equal nil "nil") results in true

10. BUG: self becomes nil in the middle of a method invocation

11. TestModel := nil recoverable?

12. Bug with RichTextPresenter showOn: (nil asValue) ?

 

 
Powered by phpBB® Forum Software