G
gz
Suppose I have the below code:
FileStream fs1 = new FileStream(...);
FileStream fs2 = new FileStream(...);
try
{
fs1.Write(...)
fs2.Write(...)
}
finally
{
if(fs1!=null)
fs1.Dispose();
if(fs2!=null)
fs2.Dispose();
}
My question is what happens if fs1.Dispose() throws an exception.
Maybe the disk is bad and it cannot successfully write the last piece
of buffer to it. If that happens, then:
1) Do I consider fs1 disposed?
2) Is it correct that fs2 is not Disposed?
In order for this to work, I have to write:
finally
{
try{
if(fs1!=null)
fs1.Dispose();
}
finally
{
if(fs2!=null)
fs2.Dispose();
}
}
This is very ugly, and incorrect. What happens if both fs1.Dispose()
and fs2.Dispose() throw exceptions?
Thanks,
gz
FileStream fs1 = new FileStream(...);
FileStream fs2 = new FileStream(...);
try
{
fs1.Write(...)
fs2.Write(...)
}
finally
{
if(fs1!=null)
fs1.Dispose();
if(fs2!=null)
fs2.Dispose();
}
My question is what happens if fs1.Dispose() throws an exception.
Maybe the disk is bad and it cannot successfully write the last piece
of buffer to it. If that happens, then:
1) Do I consider fs1 disposed?
2) Is it correct that fs2 is not Disposed?
In order for this to work, I have to write:
finally
{
try{
if(fs1!=null)
fs1.Dispose();
}
finally
{
if(fs2!=null)
fs2.Dispose();
}
}
This is very ugly, and incorrect. What happens if both fs1.Dispose()
and fs2.Dispose() throw exceptions?
Thanks,
gz