Search code examples
javaosgiapache-httpclient-4.xapache-karaf

Strange behavior using Apache HttpClient


I am new to OSGi and it's the first time I am using Apache HttpClient under OSGi.

When I execute this code...

try {
        System.out.println("> Creating Method Request");
        HttpGet httpGet = new HttpGet(baseUri + codec.encode(data));

        System.out.println("> Creating Client");
        CloseableHttpClient httpclient = HttpClients.createDefault();

        System.out.println("> Use Objects");

    } catch (Exception ex) {

        System.out.println("> Exception " + ex.getCause());

    } finally {

        System.out.println("> Finally");
    }

, I get this behavior: "> Creating Client" gets printed followed by "> Finally". No exception is caught but ">Using Objects" is never print.

Does anyone know what could be causing this? Thanks in advance.


Solution

  • Because an Error was thrown rather than an Exception? Change the catch (Exception to catch (Throwable and see what happens.