How to customize java.io.IOException error message on Android?

0

When Android makes an external connection and this url is not available it returns an error.

How to customize an error as in the example below:

java.io.IOException: Error response: 401 Service Unavailable

for something like:

Erro: Serviço não dospinível

I hope I have been clear in the question.

    
asked by anonymous 15.05.2014 / 15:35

1 answer

2

The error is already being customized by the library / method that is producing the IOException . In this case the solution would be to capture this exception in a block catch() and throw a new IOException with the custom text. If you want to customize this text only when the% original_contains exactly the text "Error response: 401 Service Unavailable" will have to make a comparison of this string with the one that is returned by IOException (using exception.getMessage() ).

For example:

try {
    ...
    player.playAsync(url);
    ...
} catch (IOException e) {
    if ("Error response: 401 Service Unavailable".equals(e.getMessage()) {
        throw new IOException("Erro: Serviço não disponível");
    } else {
        throw e;
    }
}
    
15.05.2014 / 16:54