try-Catch not catching a NilObjectException

Hello,

i am working on an App which uses Einhugur JSONNODE Objects.

In a Thread i am doing a try-catch block to perform a Quick&Dirty fix for a NOE situation i need to explore when i have more time for the research.

So i wrote:

[code]try

If JSONNODE.Child(“resources”) <> Nil Then

End If

Catch err As NilObjectException

End Try
[/code]

But i still get a “This application must shutdown…” Message.

I also tried a:

Catch err As RuntimeException If err IsA NilObjectException ...

But i still see my App crashing.

Any clue what i am doing wrong here?

Tested with Xojo 2015 R4.1 on OS X (El Cap.)

Hmm, put a break in the App.UnhandledException event and hope you land there…

Are you sure the error is happening where you think it is?

I have currently a “Return True” in this Event to be able to perform other tests. But i don’t want to release the App as long as this issue is not solved.

The debugger marks the line with the “If JSONNODE.Child(“resources”) <> Nil Then” because of a NOE at this position.

A quick test shows it raises a KeyNotFoundException here.

So maybe you catch wrong type?

Well, it may depend on what is in that json node.
But if you can reproduce in small example, we appreciate a bug report in Feedback.

[quote=247746:@Christian Schmitz]A quick test shows it raises a KeyNotFoundException here.

So maybe you catch wrong type?

Well, it may depend on what is in that json node.
But if you can reproduce in small example, we appreciate a bug report in Feedback.[/quote]

How did you test it please? Because it seems to depend on what has (or has not) been parsed into the JSONNODE Object. I GET a JSON String from the Apple iTunes Search API via a HTTPS Socket. Most times the JSON String is fine and parses just fine. Sometimes there is additional information (Header Information) within the JSON String and the Einhugur JSONNODE fails to parse it.
The JSONNODE is in this case NOT NIL but “empty” (no Childs). But the debugger stops at “.Child(“resources”) <> Nil” and reports a NOE. The NOE is really a NOE because there are no Childs in this Node. :slight_smile:

That’s fine, I just proposed the aforementioned step to give you a chance to take a closer look at the exception (such as the message).

Damn… i am so stupid sometimes… :confused:

The Debugger stops and shows a NOE because this is an intended behaviour.
I placed a Break in the Catch Event and the Debugger stops a second time at the Break Position.

I am sorry, but i think i wasted your time. :frowning:
Thank you for your kind help :slight_smile:

You could have inserted a general Catch err As RuntimeException at the end to get all other types of exception

[code]Try

If JSONNODE.Child(“resources”) <> Nil Then

End If

Catch err As NilObjectException

Catch err As RuntimeException
BREAK
End Try[/code]

If you do catch a general RuntimeException, be sure to test for, and re-raise, the EndException and ThreadEndException.

The blanket catch seems to me in order only after thorough debugging, as a final precaution before release.

Sasha how do you find jsonnode ? Is it faster, better? Why did you choose this over th new framework? Or the old jsonitem?

Thanks for any feedback, I’m looking for alternatives and I’m really curious about this plugins ability

Regards james