I always thought this would shut down FS, but it would not.Static void main (string [] ARGs) {filestream FS = NULL; try {FS = new filestream (@ "D: \ data.txt", filemode. create); byte [] bytes = new utf8encoding (). getbytes ("try"); FS. write (bytes, 0, bytes. length); throw new exception (); // The exception is not processed} finally {byte [] bytes = new utf8encoding (). getbytes ("finally"); FS. write (bytes, 0, bytes. length); If (FS! = NULL) fs. Close ();}}
To effectively disable FS in this way:Static void main (string [] ARGs) {try {filestream FS = NULL; try {FS = new filestream (@ "D: \ data.txt", filemode. create); byte [] bytes = new utf8encoding (). getbytes ("try"); FS. write (bytes, 0, bytes. length); throw new exception (); // The exception is not processed} finally {byte [] bytes = new utf8encoding (). getbytes ("finally"); FS. write (bytes, 0, bytes. length); If (FS! = NULL) fs. Close () ;}} catch {Throw ;}}
Try catch finally