By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

How to catch (or prevent) "Found a low surrogate char..." error

P: n/a
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 UnicodeEncoding.GetString(bytes)...

However, when the byte array doesn't contain value Unicode values, I get a
"Found a low surrogate char without a preceding high surrogate at index..."
exception.

I understand why the error occurs, but I don't understand how to catch (and
ignore) the exception. For example, fhe following doesn't work...

Try
Dim c As String = enc.GetString(bytes)
Catch ex As Exception
...
End Try

.... the Catch is never entered.

So, how do I...

1) catch the exception

OR (preferably)

2) do a "test" on the byte array to ensure it contains valid Unicode values
BEFORE I actually do the conversion (which to me would seem to be more
efficient than causing/catching/ignoring an exception).

BTW: this is .NET 1.1

????

Mar 28 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.