javaandroidexceptionmalformedurlexception

Java Exceptions, pass data from try block to the handler


I am catching a MalformedURLException and I would like the stack trace to include the malformed url.

The methods getMessage() and getLocalisedMessage() don't show the entire URL, I cannot reference the url declared in the try block and if I initialise the variable outside the block I get an error pointing out that the URL might not ever get initialised.

I am wondering if there is a way to pass the url from the try block to the handler.


Solution

  • When you declare the URL outside the try block init it to null