Streamwriter error handling

Starr Duskk
Starr Duskk used Ask the Experts™
on
I am using streamwriter to write to a file. It faiils to create a file but doesn't generate an exception.

How do I find an error?

try
  Dim objStreamWriter As StreamWriter
            objStreamWriter = File.CreateText(UniquefileName)
            objStreamWriter.Write(strOutput)
            'Close the stream
            objStreamWriter.Close()


        Catch ex As Exception
            SendError(ex.Message)
        End Try
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
use

objStreamWriter.Flush();
objStreamWriter.Close()

Use Flush before Close.

Hope this will solve your problem;
Starr DuskkASP.NET VB.NET Developer

Author

Commented:
how does flush help me find the error?
what does that do?
 
while using resource sensitive object use using
 Try
            Using objStreamWriter As New StreamWriter(UniquefileName)
                objStreamWriter.Write(strOutput)
            End Using
        Catch ex As Exception
             SendError(ex.Message)
        End Try

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial