This content has been marked as final. Show 4 replies
rohit pathak wrote:When an exception is thrown, you have two choices:
iwhen internet is down , it throw an exception on Connection.connect() ,
connect() is void type , it is not returning anything, that's why i can not handle it
1) Catch it and actually handle it. This means whatever failed, you have to make it work. Maybe by trying again, maybe be providing a default value.
2) If you cannot to #1, then you should not catch the exception in the first place. Or, if you do catch it, wrap it and rethrow it.
So, for example, in your case, if your code is:
If the "establish" part fails, you obviously can't do the "use" part, and this overall task has failed. That happens sometimes.
Establish connection. Use connection.