How can I customize java.io.IOException? | Thales IoT Developer Community
November 6, 2014 - 12:47am, 2539 views
Hello,
I am working with TC65.My application performs certain calculations. In order to do the final calculation the application request a data from a Servlet using http post request.
I have a method to create a backup file in memory flash in order to copy the servlet data to read it then if there is a GSM problem connection.
If I disconnect the antenna of the modem or there is a problem with the GMS network I receive an exception error instead of the expected data from the backup file.
What is your suggestion?.Should I need to customize the error exception to run the method I have to read the data from the backup file? How Can I do it?
I have a method readFromFile() in order to return the value if there is a problem with the network but I can't avoid the exception error.
Regards,
public int processServerResponse(HttpConnection http,InputStream iStream)
throws IOException{
try {
}catch ( Exception ex ){
System.out.println( "Http : ex : " + ex.getClass() + " : " + ex.getMessage() );
ex.printStackTrace();
}
return result;
}
}
//receiving data from Servlet in order to do the final calculation
try {
post.enviarPost();
Thread.sleep(100);
} catch (IOException ex) {
ex.printStackTrace();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
// do the final calculation
FinalValue=(double)(value *result)/12;
System.out.println("Tarifa a pagar:" + FinalValue);
Hi,
I'm not sure if I've got your point properly.
If you try to get some information from the network and then you get the exception because of some exceptional situation (i.e. no connection because of antenna disconnection) you reach the catch block where you can take some actions like print stack trace, throw another exception, set some flag... Then you go further In this case I can see that your processServerResponse() returns a value. If your network reading method returns something that is not the server response you can read the file then. You can return an object that contains more information that simple int, you can set some flag when connection fails... It depends on what you need.
Regards,
Bartłomiej