|
Prev: Metaprogramming: Tool or toy? Case study: A law based test automaton
Next: Programming on Linux vs Windows
From: zade on 15 Jun 2008 14:27 I want to use unicode in my program, that is, wchar_t but not char. When I have to throw some exception, I have to convert the wchar_t to char and then use std exception classes. so, why the std exception are not template designed, just like basic_string or iostream? -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Martin T. on 15 Jun 2008 16:53 zade wrote: > I want to use unicode in my program, that is, wchar_t but not char. > When I have to throw some exception, I have to convert the wchar_t to > char and then use std exception classes. > so, why the std exception are not template designed, just like > basic_string or iostream? > Maybe because then you would have two separate exception base classes that you would have to catch separately which IMHO is quite beside the point for an exception base class. Personally I'd recommend to just convert to UTF-8 for the exception messages. br, Martin -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: AnonMail2005 on 16 Jun 2008 07:58 On Jun 16, 1:27 am, zade <zhaohongc...(a)gmail.com> wrote: > I want to use unicode in my program, that is, wchar_t but not char. > When I have to throw some exception, I have to convert the wchar_t to > char and then use std exception classes. > so, why the std exception are not template designed, just like > basic_string or iostream? Just derived you own exception from std::exception which takes your wchar_t and use this class to throw your exceptions. The class can do the necessary conversion w/o you having to do it every place you want to throw an exception. HTH -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Pavel Minaev on 17 Jun 2008 05:15
On Jun 16, 9:27 am, zade <zhaohongc...(a)gmail.com> wrote: > I want to use unicode in my program, that is, wchar_t but not char. > When I have to throw some exception, I have to convert the wchar_t to > char and then use std exception classes. > so, why the std exception are not template designed, just like > basic_string or iostream? In general, if you're displaying exception messages to the user, you are usually doing something wrong. Exception message is not meant to be localizable (and, indeed, why would it be, considering that it is often thrown by code that is very far from the UI layer) - rather, the code that catches the exception should inspect it to find out what it is about, and display the error message accordingly. If you really want, you can always define your own class derived from std::exception which stores std::wstring inside it, and use that for all your exceptions. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |