H
homawong
Hi,
This seems to be an obvious question but I ask anyway.
Currently, I call webservice as follow,
try
{
using (webService.someService ws = new .webService.someService())
{
// Do something
}
}
catch (System.Net.WebException ex)
{
// Catch exception
}
Sometimes I want to get some information about the webservice within
the catch block, so this structure prevent me from doing it and I have
to add another using(...) block within the catch code.
One simple way to get around it is swapping the try/catch and using,
using (webService.someService ws = new .webService.someService())
{
try
{
// Do something
}
catch (System.Net.WebException ex)
{
// Catch exception
}
}
my question is when an unhandled exception is thrown, the using(...)
block should "theorically" effective and clean up the webservice
correctly. But would there be things that might happen causing the
clean up of webservice fail? If this is the case, then with using
outside of try/catch might not be a good idea.
But if there is such things, I think the original one will also fail.
Any idea on this?
Homa Wong
This seems to be an obvious question but I ask anyway.
Currently, I call webservice as follow,
try
{
using (webService.someService ws = new .webService.someService())
{
// Do something
}
}
catch (System.Net.WebException ex)
{
// Catch exception
}
Sometimes I want to get some information about the webservice within
the catch block, so this structure prevent me from doing it and I have
to add another using(...) block within the catch code.
One simple way to get around it is swapping the try/catch and using,
using (webService.someService ws = new .webService.someService())
{
try
{
// Do something
}
catch (System.Net.WebException ex)
{
// Catch exception
}
}
my question is when an unhandled exception is thrown, the using(...)
block should "theorically" effective and clean up the webservice
correctly. But would there be things that might happen causing the
clean up of webservice fail? If this is the case, then with using
outside of try/catch might not be a good idea.
But if there is such things, I think the original one will also fail.
Any idea on this?
Homa Wong