Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reexucuting try blocks

Status
Not open for further replies.

GIGN

Programmer
Oct 6, 2000
1,082
NZ
Hi all, I have a call to Transport.send() in a try block.
Sometimes it throws an exception, which is O.K. - but I want to be able to retry the send.

This is a general question - how to ignore the error and resume normal operation? I have tried calling return.
b2 - benbiddington@surf4nix.com
 
Actually - they are re-executed, I have just adjusted my methods to make better use of exception handling - I was obviously just geting the same error occuring over anf over agian.
b2 - benbiddington@surf4nix.com
 
Hi,

If you just want to call the send method one more time you can do this:-

try
{
Transport.send();
}
catch (Exception e)
{
//put the try catch if necessary
try
{
Transport.send();
}
catch (Exception e)
{
}
}

If you want to keep on trying, you can do this but beware of infinite loop:-

while (a==0)
{
try
{
Transport.send();
a=1;
}
catch (Exception e)
{
}
}

Basically there is no way to ignore the error unless you throw the exception in the method, which would be something like 'public String getName() throws IOException'.
Another way is to use the keyword finally.

try
{
Transport.send();
}
catch (Exception e)
{
System.out.println("Error encountered : "+e);
}
finally
{
//Carry on with what you want to do here.
}

Regards,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
Yeah, I got it sussed - I just was not getting the error messages - have it going properly now. thanks,;-)
b2 - benbiddington@surf4nix.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top