swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: null objects don't yell


From: Tee Toth-Fejel
Subject: RE: null objects don't yell
Date: Tue, 9 Jan 2001 16:50:41 -0500

> -----Original Message-----
> From: Paul E Johnson [mailto:address@hidden
> Sent: Monday, January 08, 2001 4:53 PM
> To: Swarm-support
> Subject: null objects don't yell; JAVASWARMGDB
> 
> I've had this error come up a couple of times, and it is really
> frustrating. ...
> 
> Suppose model swarm loops over agents, telling them what to 
> do.  Suppose
> there is some mistake inside the method the agent is carrying out, so
> that it tries to send a message to a null object.  Java makes no error
> message, but instead it terminates the action for the whole loop right
> at that spot.  

Yes, I've had something similar happen to me three different ways in the
last two days (fortunately, I'm past the frustration stage and have reached
utter despair).
Apparently, if you have a method that is in a schedule (loops don't seem to
be necessary), and you try to call a method on a null object, Swarm cleverly
hides the expected NullPointerException and goes merrily on it's way (it
doesn't terminate for me).  I'm guessing that this feature exists because of
the Objective C/Java interface.  Or perhaps my class (in this case Heatbug)
just doesn't know what to do with unexpected exceptions, but I've never seen
that elsewhere in Java.

Fortunately, as Joshua Madden address@hidden suggested, this
"invisible" error can be caught.  e.g. (when I don't set the public member
of heat, heat.heatbugModelSwarm, then switchHeatbugList(bug) breaks
visibly):

                try {
                 heat.heatbugModelSwarm.switchHeatbugList(this);
                 }
             catch (NullPointerException ex)
                 {
                 ex.printStackTrace();
                 System.out.println("Heatbug.Step: caught invisible
exception!");
                 }
results in:
java.lang.NullPointerException
        at Heatbug.heatbugStep(Heatbug.java:358)
        at swarm.simtoolsgui.GUISwarmImpl.go(Native Method)
        at StartHeatbugs.main(StartHeatbugs.java:31)
        at intuitive.audit.Main.runProgramWithClass(Native Method)
        at intuitive.audit.Audit.main(Audit.java)
Heatbug.Step: caught invisible exception!

In case you're wondering, I'm splitting jheatbugs into two pieces for a
distributed jheatbugs demo.

Tihamer "Tee" Toth-Fejel                    Member of Technical Staff
(734) 623-2544   address@hidden      http://www.erim.org/ 
Center for Electronic Commerce, Environmental Research Institute of Michigan

 

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]