Stack Trace for Exceptions

How to get a stack-trace if the program throws an exception (or any information pointing to the position in the program from where the exception was thrown?)

Example (a typical beginner’s mistake):

PVector [] vs = new PVector [10];

for (int i=0;i<vs.length;++i) 
  vs[i].set(0,0);

When running this in processing, all it does is displaying a red NullPointerException message. I cannot see any way to find out where in the program this was thrown. (Ideally, I would like to see a stack trace). If this is not possible, what is the suggested approach in Processing to debugging (unexpected) exceptions, in particular if the programs get bigger?

(processing 4.4.4 on Ubuntu 24.04, just in case that’s a known platform issue)

– Peter Lammich

Hello @plammich ,

I am using W10.

Processing 3.5.4 will highlight the line:

Processing 4.4.4 only shows this:

I have observed that error checking does not seem to work in latest versions.

There may be an issue regarding this here:
GitHub · Where software is built

PVectors need to be initailized first:

for (int i = 0; i < vs.length; ++i) 
  {
  vs[i] = new PVector(0, 0);  // Initialize each PVector
  }

for (int i=0;i<vs.length;++i)
  {
  vs[i].set(0,0);
  }

:)

1 Like

Interesting. So a bug in processing 4.4.4? (One that makes it basically unusable for any semi-serious use). I’ll check if I find it in the issue tracker, and report it there otherwise.

btw: of course PVectors need tio be initialized, I just posted an example for a typical (beginner’s) mistake, that becomes really hard to debug without exception stack trace.

1 Like

Just an observation for now.

@stefterv Can you comment on this? Thanks in advance.

I sometimes share for the larger community; it may not be obvious to someone new here and perusing the topics.

I generally temper my enthusiasm with restraint but other times get immersed in a topic.

I will stop now… :)

1 Like

Hi @glv thank you for the tag! Could you quickly check if this is new in the 4.4.x versions by running 4.3?

I would need to know if it is a regression since those versions, then we can fix it. Otherwise it might be a deeper issue needing more attention.

Okay tested it right now, seems to be a regression in 4.4.x. Not sure what causes it but at least gives me an idea on where to look.

1 Like

Tracked down the underlying issue that is causing this, so at least it is understood why this is happening

2 Likes