summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/read.n24
1 files changed, 24 insertions, 0 deletions
diff --git a/doc/read.n b/doc/read.n
index 2a865da..66e6c30 100644
--- a/doc/read.n
+++ b/doc/read.n
@@ -53,6 +53,8 @@ which \fBfconfigure\fR will alter input.
.SH "ENCODING ERRORS"
.PP
Encoding errors may exist, if the encoding profile \fBstrict\fR is used.
+Encoding errors are special, as an eventual introspection or recovery is
+possible by changing to an encoding which accepts the data.
An encoding error is reported by the POSIX error code \fBEILSEQ\fR.
.PP
In blocking mode, the error is directly thrown, even, if there is a
@@ -65,6 +67,28 @@ in the error dictionary.
In non blocking mode, first, any data without encoding error is returned
(without error state).
In the next call, no data is returned and the \fBEILSEQ\fR error state is set.
+.PP
+Here is an example with an encoding error in UTF-8 encoding, which is then
+introspected by a switch to the binary encoding. The test file contains a not
+continued multi-byte sequence at position 1 (\fBA \\xC3 B\fR):
+.CS
+% set f [open test_A_195_B.txt r]
+file35a65a0
+% fconfigure $f -encoding utf-8 -profile strict
+% catch {read $f} e d
+1
+% set d
+-data A -code 1 -level 0
+-errorstack {INNER {invokeStk1 read file35a65a0}}
+-errorcode {POSIX EILSEQ {invalid or incomplete multibyte or wide character}}
+-errorinfo {...} -errorline 1
+% tell $f
+1
+% fconfigure $f -encoding binary -profile strict
+% read $f
+ÃB
+.CE
+ToDo: -data is TIP 653 and may be removed here or explained.
.SH "USE WITH SERIAL PORTS"
'\" Note: this advice actually applies to many versions of Tcl
.PP