Today, when there is a mental block, you need a hand to verify that my logic is not fubar'ed.
Traditionally, I would make an i / o file similar to this:
FileStream fs = null; // So it visible in the finally block try { fs = File.Open("Foo.txt", FileMode.Open); /// Do Stuff } catch(IOException) { /// Handle Stuff } finally { if (fs != null) fs.Close(); }
However, it is not very elegant.
Ideally, I would like to use the using block to get rid of the filter when done, however I'm not sure about the synergy between use and try / catch.
Here is how I would like to implement the above:
try { using(FileStream fs = File.Open("Foo.txt", FileMode.Open)) {
However, I am concerned that a premature exit (through an exception) from within the used block may not allow the executing block to complete execution and clear it. Am I just paranoid, or will it work the way I intend it?
Arena
source share