473,386 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

If An Exception During using "(StreamWriter..."

Hi,

If there is an exception during writing a file with StreamWriter how
do you abort the creation of the new file? Due to introducing a bug
an existing file was lost (backed-up, fortunately) when the "Write"
hit the bug. The incomplete file closed and overwrote its
predecessor. How do I prevent this from happening again? The
catches didn't.

The abbreviate code is:

using (StreamWriter SW = new StreamWriter(Filepath))
{
try
{
Write(SW);
}
catch (Exception e)
{
MessageBox.Show(e.Message, "...");
throw;
}
}
catch (Exception e) { MessageBox.Show(e.Message, "..."); }
Thanks,
Gary
Mar 13 '07 #1
3 2454
VJ
First backup your original file. write your file in a temp location, and
then copy it over to the new location. Now what happens at copy over,
restore from backup. So the file is place safe, if your back failed, that
might a situation. So the other option is to store incremental parts of
information in separate files, so not the entire program's data is lost, and
some recovery is available. Again if you access to many files it might be
slow to program, so essentially its balance of what's important to you.

The software can only to a extent provide fail safe mechanism, using
computers you need to learn to backup, else you are in trouble.

Did I answer your question or ramble too much??

VJ

"Gary Brown" <ga********@charter.netwrote in message
news:eX**************@TK2MSFTNGP03.phx.gbl...
Hi,

If there is an exception during writing a file with StreamWriter how
do you abort the creation of the new file? Due to introducing a bug
an existing file was lost (backed-up, fortunately) when the "Write"
hit the bug. The incomplete file closed and overwrote its
predecessor. How do I prevent this from happening again? The
catches didn't.

The abbreviate code is:

using (StreamWriter SW = new StreamWriter(Filepath))
{
try
{
Write(SW);
}
catch (Exception e)
{
MessageBox.Show(e.Message, "...");
throw;
}
}
catch (Exception e) { MessageBox.Show(e.Message, "..."); }
Thanks,
Gary


Mar 13 '07 #2
>If there is an exception during writing a file with StreamWriter how
>do you abort the creation of the new file? Due to introducing a bug
....
First backup your original file. write your file in a temp location, and
then copy it over to the new location. Now what happens at copy over,
....

That is what I was afraid of. Some OS's (VMS? TOPS-20?) allowed
you to just bail out and the file system was none the wiser.
Did I answer your question or ramble too much??
No, that was fine.

Thanks,
Gary
Mar 13 '07 #3
>>If there is an exception during writing a file with StreamWriter how
>>do you abort the creation of the new file? Due to introducing a bug
...
>First backup your original file. write your file in a temp location,
and then copy it over to the new location. Now what happens at copy
over,
...

That is what I was afraid of. Some OS's (VMS? TOPS-20?) allowed you
to just bail out and the file system was none the wiser.
Vista apparently has a transactional file system, so it might be possible
there.

Hans Kesting
Mar 14 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: gregory_may | last post by:
I have an application I created called "JpegViewer.exe". It simply loads a Jpeg file and displays in on the screen. It works great, in my lab. When I am using it at a customer site, things...
2
by: Chris Herring | last post by:
Hi there: Well, let me start off by saying that I am a Visual Studio drag and drop weenie, not a real programmer. So I tend to get confused when things do not look like the instructions said they...
5
by: Peter Steele | last post by:
We have an application that when it runs in the IDE in debug mode an unhandled exception is occurring in a system header file associated with STL stirngs. The actual statement that crashes is ...
5
by: Lyle A. Sieren | last post by:
I posted this earlier with another question but did not explain myself well... How do get a line feed character on the end of a line using the streamwriter.writeline fuction? Following are a list...
3
by: Mads Westen | last post by:
Hi, I'm making some changes to my program, because I need to write with Codepage 850. Before I used FileStream, but I found code to use with StreamWriter instead. My problem is, that I don't...
7
by: Søren Dreijer | last post by:
Hi, I have a mixed C#, managed C++ and unmanaged C++ project. The managed class calls a method which exists in an unmanaged singleton class. During the entire lifetime of the application, this...
0
by: Tamer Ibrahim | last post by:
Hi, Sometimes, I got the following error message when I use ajax calendar control on some aspx pages : Object reference not set to an instance of an object. Description: An unhandled exception...
0
by: mm3178 | last post by:
Hello, I have a windows service application and I want to log the whole process inside it. I am currently using streamwriter to log into a txt file. How do we log everytime on a same line...
0
by: raghudr | last post by:
Hi all, I am coding for displaying a splash screen until a big job is finished.I am getting an exception:only during the first start of the system.Rest all the time it is working fine. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.