Error: 4invalid UTF-8 sequence :: How can I catch this?? (or otherwise handle it)

Daniel Keep daniel.keep.lists at gmail.com
Wed Oct 21 20:21:52 PDT 2009


Charles Hixson wrote:
> I want to read a bunch of files, and if the aren't UTF, then I want to
> list their names for conversion, or other processing.  How should this
> be handled??
> 
> try..catch..finally blocks just ignore this error.

> type stuff.d
import std.stdio;
import std.utf;

void main()
{
    try
    {
        writefln("A B \xfe C");
    }
    catch( UtfException e )
    {
        writefln("I caught a %s!", e);
    }
}

> dmd stuff && stuff
A B I caught a 4invalid UTF-8 sequence!

Works for me.


More information about the Digitalmars-d-learn mailing list