Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems
Managing errors in a different language

Posted by nicolascastagne (nicolascastagne), 6 April 2005
Hi all,

We are using Tcl for supporting a user-dedicated langage within a big GUI-based application developped in C++.
The user will use this language to manage some sort of "macros".
Nothing particular so far : tcl is adequate to this usage.

However, we encounter huge difficulties to manage the errors.

Indeed, we need to translate the errors in the appropriate language : italian, french, etc.

This is not a problem for the proc we provide ourselves. But how could we handle the errors generated within Tcl ?
For example, in case of a syntax error, we cannot display the basic Tcl output errorInfo to our user.

A solution would be to get a "error code" from Tcl, that we could "expand" in the appropriate string form. But, so far, we do not succeed in recovering any error code in the C++ code - only the wall char* errorInfo .
Is that possible ? Where can we find a description of all the error codes Tcl may generate ?

More generally, since Tcl is widely used for managing languages within apps... How is this problem handled usually ?

Thx in advance !

Posted by admin (Graham Ellis), 10 April 2005
Hi, Nicolas ... I'm not ignoring the question, but this isn't one that I've come across personally and I was hoping that someone else had ...

Posted by Custard (Custard), 10 April 2005

I just wrote a lengthy post that completely missed the point after I re read your post..

Try no,2


According to my book,

catch { your code } msg

Will run 'your code' and if there is an error, the catch returns a 1, and msg is set to whatever the error was.
If 'your code' was successful, catch returns a 0, and msg contains the return value from 'your code'

Is this any use?


Posted by admin (Graham Ellis), 11 April 2005
Ah ... I had forgotten / overlooked catch. It might well be the trigger that Nicolas is looking for.

If that other lengthy piece of text is of general interest / as a tip on Tcl, do feel free to start a new thread, "B"  

Posted by Custard (Custard), 11 April 2005

(Graham, I will post here as it is sort of pertinent to the subject of this thread even though the OP may have solved this bit already.
I just like this way as it enables use of java-like message bundles.
And you're lucky it was still in my cut-buffer!)

This is one of the briefs in my current project (which is admittedly perl, but the prinicples are the same).

What I have is a config file with entries for country/language like

country = EN
language = EN

And a class (in perl) which is initialised with these codes, and looks for a message bundle in a config directory. In my case, the message bundle would be config/Messages_EN_EN.

error.cannotload = Cannot Load File ()
msg.started = Started () at ().

The message bundle (suspiciously similar in format to the Java message bundles) is loaded into a hash.
Empty parens () are substituted with args in the message function.

Then you can call the message function like  

message "error.cannotload" "file.txt"

Translate my description into TCL-speak, and write your 'init' and 'message' function, and you're close.

I hope this is what you mean, and is helpful.

For perl there are various ways of doing it, and I'm sure there are for TCL, and maybe there is something out there. I rolled my own because it suited me to.



Posted by admin (Graham Ellis), 12 April 2005
That takes me back to my days of CAD software writing ... with support for English and Norwegian.  All meesages numbered, and the appropriate message file loaded without anything so fancy as a config file (but it was a very long time ago).   We also had a reverse translation setup, as keywords and single letter confirmations entered were best translated too.

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: • WEB: • SKYPE: wellho