Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6057451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:29:24+00:00 2026-05-23T08:29:24+00:00

I’ve got a strange problem with a try/catch block I’m using. I’ve got this

  • 0

I’ve got a strange problem with a try/catch block I’m using. I’ve got this method, which just gets some data from a remote service and stores it.

public WFSGetCapabilitiesResponse wfsGetCapabilities(String url) {
    WFSGetCapabilitiesResponse response = new WFSGetCapabilitiesResponse();

    try {
        WFSDataStore data = loadWFSCapabilities(url);
        String[] typeNames = data.getTypeNames();
        ArrayList<WFSFeatureTypeBase> wfsLayers = new ArrayList<WFSFeatureTypeBase>();
        for (int i = 0; i < typeNames.length; i++) {
            String typeName = typeNames[i];

            WFSFeatureTypeBase newLayer = new WFSFeatureTypeBase();
            newLayer.setTypeName(typeName);
            newLayer.setName(typeName.split(":")[1]);
            newLayer.setTitle(data.getFeatureTypeTitle(typeName));
            newLayer.setAbstract(data.getFeatureTypeAbstract(typeName));
            newLayer.setServiceUrl(url.split("\\?")[0]);

            wfsLayers.add(newLayer);
        }
        response.setWFSLayers(wfsLayers);
    } catch (IOException e) {
        response.setError(WCSCapabilitiesResponse.IO_EXCEPTION);
        response.setErrorMessage(e.getMessage());
        response.setSuccessful(false);
        e.printStackTrace();
        return response;
    }
    return response;
}

If I run with this code, I get a null pointer exception (‘data’ is null, but don’t really know if it’s relevant). However, if I remove the return statement from my catch block everything is fine.

The strange thing is, the IOException is not being caught in either case, so I can’t see why it’s having such an impact.

So again, with the return in the catch block it doesn’t work, without it it does… I really can’t see why this would happen.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:29:25+00:00Added an answer on May 23, 2026 at 8:29 am

    Well, my first thought is that the catch block can only make a difference if an IOException is thrown – so we know for sure that that’s happening. And likewise we know that without the catch block, this exception will propagate out of the wfsGetCapabilities method (presumably you added an appropriate throws declaration when you removed the catch block).

    So chances are, in the “working” case, the calling code is catching the IOException higher up and handling it in such a way that your method appears to work judging by the output. Of course your method didn’t work, and threw an exception, but perhaps there’s a default fallback (or similar) which is invoked in an error case?

    So that’s the “strange” part hopefully dealt with. As for the “problem” part, if you’re getting a NullPointerException thrown with the catch block, but not without it, it’s clear that your catch block logic is not quite right and is causing this problem. From what you’ve posted it doesn’t look like any of those immediate references would be null – take a look at the stack trace and determine from which line the exception is thrown, then fix it as you would any other NPE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I've got a string that has curly quotes in it. I'd like to replace
I have a JSP page retrieving data and when single or double quotes are
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.