By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,965 Members | 1,479 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,965 IT Pros & Developers. It's quick & easy.

c++ exception with a non-ascii message

P: n/a
Hi,
I am c++ standard exceptions like out_of_range, but want it to have
some nonascii message. However what returns a char* and the class is
not templated.
Do I need to write my own exception class for this purpose?
Same problem I am facing with fstream. The open function is
non-templated and takes a char* as file name. The file is always ascii,
thus no wstream is needed, but the file-name sometime contains
non-ascii character.

Thanks

Oct 27 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
toton wrote:
Hi,
I am c++ standard exceptions like out_of_range, but want it to have
some nonascii message. However what returns a char* and the class is
not templated.
Do I need to write my own exception class for this purpose?
Yes.

It's probably a good idea to write your own exception hierarchy anyway.
The standard exceptions are way to broad to be useful in real programs.
Same problem I am facing with fstream. The open function is
non-templated and takes a char* as file name. The file is always ascii,
thus no wstream is needed, but the file-name sometime contains
non-ascii character.
This one comes up pretty often. I think it should be a FAQ. Basically,
you have to convert from wide to narrow characters yourself. Some
compilers have a templated constructor as an extension, but the
standard C++ version doesn't. I'm not sure whether the standards
comittee intends to fix this or not.

Regards,
Bart.

Oct 27 '06 #2

P: n/a
toton wrote:
Same problem I am facing with fstream. The open function is
non-templated and takes a char* as file name. The file is always ascii,
thus no wstream is needed, but the file-name sometime contains
non-ascii character.
In C++0x, file streams will have overloaded constructors and open()
member functions. One overload will take a const char* and the other
will take a const string&.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Oct 27 '06 #3

P: n/a
In C++0x, file streams will have overloaded constructors and open()
member functions. One overload will take a const char* and the other
will take a const string&.
I don't see that move solving non-ASCII character file name problem,
however.

Ben
Oct 27 '06 #4

P: n/a
Hello,

toton wrote:
I am c++ standard exceptions like out_of_range, but want it to have
some nonascii message. However what returns a char* and the class is
not templated.
I think UTF-8 has been designed to serve this purpose, as extension of
ASCII which needs only 8-bit chars to work. You should not need to do
anything special, if UTF-8 is supported on your platform. The same
holds for filenames.

Bernd Strieder

Oct 27 '06 #5

P: n/a

Bart wrote:
toton wrote:
Hi,
I am c++ standard exceptions like out_of_range, but want it to have
some nonascii message. However what returns a char* and the class is
not templated.
Do I need to write my own exception class for this purpose?

Yes.
Thanks. I will use my own exception hierarchy, not inheriting from
std::exception.
It's probably a good idea to write your own exception hierarchy anyway.
The standard exceptions are way to broad to be useful in real programs.
Same problem I am facing with fstream. The open function is
non-templated and takes a char* as file name. The file is always ascii,
thus no wstream is needed, but the file-name sometime contains
non-ascii character.

This one comes up pretty often. I think it should be a FAQ. Basically,
you have to convert from wide to narrow characters yourself. Some
compilers have a templated constructor as an extension, but the
standard C++ version doesn't. I'm not sure whether the standards
comittee intends to fix this or not.
At present I am converting it using current locale. But looks it is not
always possible to have such conversion.
Regards,
Bart.
Oct 27 '06 #6

P: n/a
benben wrote:
>
>In C++0x, file streams will have overloaded constructors and open()
member functions. One overload will take a const char* and the other
will take a const string&.

I don't see that move solving non-ASCII character file name problem,
however.
I don't know what the "non-ASCII character file name problem is." If
your OS uses a character encoding other than ASCII, presumably your
compiler supports it, as well. That's not a standards issue.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Oct 27 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.