Try and catch exceptions for StreamWriter