473,386 Members | 1,647 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.

Handling Error - "Low Surrogate char"

I just ran into this problem also. (undocumented exception thrown when
Streamwriter is handed a buffer with wierd characters in it).

I was also able to get around it by specifying utf8 as the encoding
for Streamwriter. (Thank you Amy L!)

But I have some questions:
1- Isn't utf8 supposed to be the default mode for streamwriter? If so
why does specifying the default fix the problem?

2- I had opend up the file for appendding and was executing a
"WriteLine(String);" command when I got that exception. The problem is
the streamwriter handle is now 'broken'. You can't write anything
else to the file, you can't close it. The only way around it this
problem is to exit the program.
This seems like a bug in the streamwriter, it should have at the very
least closed the handle so I wouldn't have to exit the program.

Thanks
Phil Ouellette.
Nov 16 '05 #1
1 1799
Phillip <sp**@vwars.com> wrote:
I just ran into this problem also. (undocumented exception thrown when
Streamwriter is handed a buffer with wierd characters in it).

I was also able to get around it by specifying utf8 as the encoding
for Streamwriter. (Thank you Amy L!)

But I have some questions:
1- Isn't utf8 supposed to be the default mode for streamwriter? If so
why does specifying the default fix the problem?
When you construct a UTF8Encoding object, you can specify whether or
not it should throw an exception when an invalid encoding is detected.
I suspect that the one used by default doesn't have the same setting
for that as the one you used (however you constructed it, or whether
you used Encoding.UTF8).
2- I had opend up the file for appendding and was executing a
"WriteLine(String);" command when I got that exception. The problem is
the streamwriter handle is now 'broken'. You can't write anything
else to the file, you can't close it. The only way around it this
problem is to exit the program.
This seems like a bug in the streamwriter, it should have at the very
least closed the handle so I wouldn't have to exit the program.


That certainly sounds odd. Could you post a short but complete program
which demonstrates the problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

If I can confirm it, I'll try to make sure it gets fixed.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

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

Similar topics

3
by: Graham | last post by:
On page 89 of Stroustrup's book "The C++ Programming Language" 3rd Ed. He says that multidimensional arrays are best avoided outside low-level code. What precisely does he mean by low-level...
12
by: Vaca Louca | last post by:
Hello, I write an ISAPI authentication module which uses Berkeley DB and want it to be as efficient as possible. Both ISAPI and BerkeleyDB use arrays of chars (char *) to pass and receive...
2
by: privetv7 | last post by:
ppl... HELP!!!!! i don't know how to convert String into char..... for example i can do String input; int number; input = JOptionPane.showInputDialog( "Enter what ever" ); number =...
26
by: =?gb2312?B?wNbA1rTzzOzKpg==?= | last post by:
i wrote: ----------------------------------------------------------------------- ---------------------------------------- unsigned char * p = reinterpret_cast<unsigned char *>("abcdg");...
34
by: arnuld | last post by:
what is the difference between these 2: char name = "hackers"; char* name = "hackers";
0
by: =?Utf-8?B?RGF2aWQ=?= | last post by:
I need to convert an incoming byte array to a Unicode string, when (if) that byte array contains valid Unicode values (sometimes it doesn't). I've been trying to use...
20
by: liujiaping | last post by:
I'm confused about the program below: int main(int argc, char* argv) { char str1 = "abc"; char str2 = "abc"; const char str3 = "abc"; const char str4 = "abc"; const char* str5 = "abc";
4
by: Virtual_X | last post by:
some function make the data type of it's parameters as "const char*" why not use char or char* instead what would be different
3
by: Mahesh | last post by:
#include <stdio.h> #include <string.h> #include <malloc.h> int main(void) { int key = 120; char *s = "String to Encrypt using XOR"; char *ss = s; char echar; char dchar;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.