Post by et99Post by gregPost by et99Is there a good place to lookup the various error codes returned by tcl commands?
try {
set f [open /some/file/name w]
} trap {POSIX EISDIR} {} {
puts "failed to open /some/file/name: it's a directory"
} trap {POSIX ENOENT} {} {
puts "failed to open /some/file/name: it doesn't exist"
}
How did the writer of this example know about these two error cases
since they are not documented in the manual under either try or open.
Also, are POSIX error codes system independent?
Hello;
https://www.tcl.tk/man/tcl8.6/TclCmd/tclvars.htm#M12
source code tcl 8.6
./tcl8.6.14/win/tclWinError.c
/.tcl8.6.14/generic/tclPosixStr.c
https://en.wikipedia.org/wiki/Errno.h
Thanks for the links.
I was afraid this was probably the only way to get the codes.
I think this could make a useful TIP - to add an error section to all
command man pages as is done in the linux man pages.
If I were 30 years younger, with the inherent time and energy, I might
have volunteered to do this, since it is obviously a tedious and perhaps
thankless job.
I guess I will just stick to using my if-catch-template and not try to
differentiate the particular errors. Besides, only I ever use my
programs anymore :)
Thank you for the words and the initiative.
Reality is worse. We are on 3 platforms.
So, we try to get the same error code on all of them.
Errors come often from system calls. On Posix systems, they are just put
up to the script. On WIndows, Windows error codes are mapped to possix
error codes, which works more or less...
Remark that error codes are also available by catch.
The advantage of try is that you have a cleanup case, which is always
executed, even on error and on return.
so:
proc t {fn} {
try {
set f [open $fn]
set d [read $f]
return $d
} trap ...
} on ...
} finally {
if {[info exists f]} {close $f}
}
}
Closes the file in any handling case. It is beautiful, that the finally
happens after the return command and the return still works.
This is a constructed example. But it might be handy.
Take care,
Harald