I would like to use Unicode with the std::exception class (deriving from it). The problem is that the what() message is char*, not wchar_t*. I don't usually worry too much about the what() message, but I was just wondering how this would be done. Should I use the WideCharToMultiByte() function from the WinAPI to do the conversion? This seems like an awful lot of work for such a trivial problem.
Do you have a particular reason for the returned error message to be a UNICODE string?
You can't override the what() in the derived class with a function that return const wchar_t*, but you could add an addition method which uses WideCharToMultiByte.
You can also pass an ANSI string to the UNICODE version of the printf family of functions, and it will convert it for you as part of the foratting operation. This might be a good options if you want to build a longer string. Esp. if it's for debugging/diagnostic purposes.
If you want to display a string to an end user, you might want to consider a different approach. To use the returned ANSI string as a key to the real (UNICODE) message. Which could even be in a different language.
Its more of the fact that my entire application is written in Unicode, and I may want to pass a Unicode string literal into the what message if I need to throw an exception, which of course would cause a compile error.
Either encode the string in UTF-8, or cast a wchar_t * to char * and make sure you cast back the return value of what() everywhere. Or don't use what() at all.