NullRef exception

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

braza
Posts: 32
Joined: 02 Jan 2014, 21:50

NullRef exception

Postby braza » 30 Aug 2014, 23:40

Hi,

I have the following piece of code:

Code: Select all

   
            try
            {
                world.getManager(TurnManager.class).NewSimulationCycle();
                world.setDelta(1.0f);
                world.process();
            } catch (Exception ex)
            {
                trace(ExtensionLogLevel.ERROR, "world simulation processing error: " + ex.getMessage() + " " + ex.toString());
                ex.printStackTrace();
            }


Sometimes NullRef exception happecns inside try block, somewhere deeper. But I expected to get whole stacktrace to identify the place, but I dont get it in logs:
31 авг 2014 | 02:45:59,485 | ERROR | SFSWorker:Ext:2 | Extensions | | {RaffSquad}: world simulation processing error: null java.lang.NullPointerException

Any hints how to get the stacktrace?
User avatar
Lapo
Site Admin
Posts: 21081
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: NullRef exception

Postby Lapo » 31 Aug 2014, 18:37

Hi,
the printStackTrace() method will send the stack trace to the default output which is not captured by the logs.

If you simply remove the try/catch block you will see all the details because the Exception will be caught by the Extension Manager which in turn will give you all the details.
Another way to deal with stack traces is to use an utility object in SFS API called ExceptionMessageComposer.

Example:

Code: Select all

try
{
  //... some code
}
catch(Exception ex)
{
   ExceptionMessageComposer emc = new ExceptionMessageComposer(ex);
   trace(emc.toString());
}


The object also allows to include additional comments, descriptions and custom fields to provide more details about a specific error. Anyways, the snippet above is sufficient to get the stack trace and the exception details.

hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 13 guests