I have the following:
     try {
        response.statusCode = urlConnection.getResponseCode();    
     } catch(IOException e) {
        throw e;
     }
I look at the debugger and e = UnknownHostException   
After the throw I have:
    try {
        NetworkResponse response = NetworkHelper.getByURL(url);
     } catch(Exception e) {   <------- IT LANDS HERE, BUT e=null
        ExceptionHelper.announce(e);        
        throw e;
    }
So after the throw my catch block gets the exception but it's null. The debugger shows e=null.
I have no idea why this would happen.
The getMessage() method of Throwable class is used to return a detailed message of the Throwable object which can also be null. One can use this method to get the detail message of exception as a string value.
Returns: the cause of current Throwable. If the cause is nonexistent or unknown, it returns null.
What Causes NullPointerException. The NullPointerException occurs due to a situation in application code where an uninitialized object is attempted to be accessed or modified. Essentially, this means the object reference does not point anywhere and has a null value.
Throw an ExceptionThrowing is the right approach when null represents an unrecoverable failure. For example, imagine calling a helper method that gives you a database connection string. Imagine the method doesn't find the connection string, so the method gives up and returns null .
I don't even see the point of catching the exception if you just immediately rethrow it.  Add a throws IOException to that method and let the other catch handle it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With