Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FileOutStream Exception
#1
I am getting the following exception:

'Ã' is not representable in the encoding 'US-ASCII'

With this code snippet:

Code:
fileLogDump.FmtStr(strOutMessage);
fileLogDump.NewLn();
fileLogDump.Flush();

Is there an easy method to clean up non-Ascii characters out of a string before passing it to a TextOutStream?

BTW: This is in a Try/EndTry block and the exception is not getting caught...
Wuench
My Home Theater/Automation Website

[THREAD=5957]BlueGlass CQC Config[/THREAD]
[THREAD=10624]Wuench's CQC Drivers[/THREAD]
Reply
#2
Are you getting a CML exceptoin and it's not getting cause by the Catch? Or is it some C++ exception leaking out because it wasn't correctly caught and translated?

On the other issue, perhaps you can just set a different encoding on the stream? Something like Latin1 (ISO-8859-1) is a full 256 code point encoding, so there won't be any invalid character issues, though if the source content is in some unusual encoding you may not get exactly the original text back.
Dean Roddey
Explorans limites defectum
Reply
#3
It is a C++ exception not getting caught in the IDE. I don't see how to set the character set on a FileOutStream.

I tried to use an XCoder but I can't figure it out. If I put the string in a buffer and try to format it out to a string using a USASCII XCoder with the Error set to replace characters I get one exception and if I try to import it into a buffer using a USASCII XCoder I get a different exception. But at least those are caught so my code moves on.

But I have this string with that character in it. I have no idea what character set that is, it's coming in from XBMC via JSON. I want to write that string to a text file and filter out those characters or whatever it takes to write the string. Can you give me an example of how to do that?
Wuench
My Home Theater/Automation Website

[THREAD=5957]BlueGlass CQC Config[/THREAD]
[THREAD=10624]Wuench's CQC Drivers[/THREAD]
Reply
#4
One of the class' constructors allows you to indicate an encoding. For string based text output streams, it doesn't matter since any text you have is Unicode and it's being written to a Unicode string buffer. But for files or memory buffers, it has to be converted to bytes and that requires that the text be transcoded to some encoding.

I'll look into why it's not catching the C++ exception and converting it.
Dean Roddey
Explorans limites defectum
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unhandled system exception in the GUI Thread gReatAutomation 9 2,222 03-23-2020, 01:03 PM
Last Post: Dean Roddey
Photo Unhandled GUI Exception simplextech 3 1,252 01-05-2020, 03:27 PM
Last Post: zra
  Unhandled system exception in GUI Thread Shaky 75 20,430 06-21-2019, 08:10 PM
Last Post: kblagron
  Unhandled Exception Scheduled Events zra 8 4,057 06-25-2015, 05:54 PM
Last Post: zra
  An unknown exception has occured... brathnach 11 4,462 11-10-2013, 06:08 PM
Last Post: brathnach
  New Exception Behavior 4.2.16? wuench 1 1,451 11-19-2012, 12:52 PM
Last Post: Dean Roddey
  unhandled exception Ron Haley 3 1,629 11-13-2012, 08:55 PM
Last Post: Dean Roddey
  Checking exception types beelzerob 5 2,671 01-29-2010, 04:40 PM
Last Post: Dean Roddey
  Driver test harness - unknown exception bph 11 5,469 09-27-2009, 09:09 PM
Last Post: bph
  DGramSocket Exception Tokens Missing wuench 9 3,455 01-01-2009, 05:28 PM
Last Post: Dean Roddey

Forum Jump:


Users browsing this thread: 1 Guest(s)