We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm looking to clean up my output panel by gracefully handling http 400 errors when I try to load an invalid url. I'm using the mapquest geolocation api to lookup latitude and longitude values for location strings. often (so it seems) the location is malformed or results in an invalid url, which is ok for my program, but prints out 10 or so lines to the console, making it difficult to troubleshoot other parts of my app.
Here's a basic example:
JSONObject jo = loadJSONObject("http://open.mapquestapi.com/nominatim/v1/search.php?format=json&q=Almería,+España"); println(jo);
I've tried catching it with an IOException (which is what it throws) but it says that it is never thrown (even though that is what it is throwing. I've also tried just an Exception, but it still prints out the long stacktrace.
Any idea on how to effectively handle this?
woah there forum autoformatter, that link should just be the href part and have the ',+Espana'.
In general, Processing doesn't let exceptions to go to the sketch. It catches them itself, then display the trace in the console, which is what you see. And that's why you cannot catch them yourself.
What is the solution then?
maybe assigning null first?
so could he say
or using try .... catch..... ?
As said, you cannot use try / catch, since there is no exception to catch.
If the purpose is to avoid spamming the console, you have to copy the code from Processing, and handle the exception yourself.
Hmm, Thanks for the ideas guys.
I ended up finding using a URI fixed the console spam:
It would be nice to have a 'verbose' flag or something to disable unnecessary logs.