wchar_t exception what()??

excuse me..

I have a question.

what method is what() wchar_t version in exception class?
Last edited on
From http://www.cplusplus.com/doc/tutorial/exceptions/

what() is a "virtual member function called what that returns a null-terminated character sequence (char *) and that can be overwritten in derived classes to contain some sort of description of the exception".

That is, what() is a virtual member (i.e. needs to be defined in a concrete derived class) that is part of the standard exception base class in the standard C++ library.

Does that answer your question?
Thanks for your reply.

I know about what() method.

but what() returns const char*.

I want to get const wchar_t* .

what about it?

The STL exception classes only work with const char*.

To do what you want is non-trivial. However, you shouldn't be throwing exceptions containing characters outside the ASCII range anyway... so a simple copy from the exception string and a wchar_t string ought to work for you:

1
2
#include <algorithm>
#include <iterator> 
1
2
3
4
5
6
7
8
9
10
catch (... e)
  {
  // Convert e.what() to a wide string
  string  cs( e.what() );
  wstring ws;
  copy( cs.begin(), cs.end(), back_inserter( ws ) );

  // Do something with it...
  wcerr << ws << endl;
  }

Hope this helps.
Oh, thanks.

these articles is very helpful for me.

Topic archived. No new replies allowed.