Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > c++ exception with a non-ascii message

Reply
Thread Tools

c++ exception with a non-ascii message

 
 
toton
Guest
Posts: n/a
 
      10-27-2006
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

 
Reply With Quote
 
 
 
 
Bart
Guest
Posts: n/a
 
      10-27-2006
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.

 
Reply With Quote
 
 
 
 
Pete Becker
Guest
Posts: n/a
 
      10-27-2006
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.
 
Reply With Quote
 
benben
Guest
Posts: n/a
 
      10-27-2006

> 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
 
Reply With Quote
 
Bernd Strieder
Guest
Posts: n/a
 
      10-27-2006
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

 
Reply With Quote
 
toton
Guest
Posts: n/a
 
      10-27-2006

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.


 
Reply With Quote
 
Pete Becker
Guest
Posts: n/a
 
      10-27-2006
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
displaying exception message from custom exception bdgreen@pacbell.net ASP .Net 2 08-18-2006 05:59 PM
Re: bizaar exception that isn't really an exception jeff ASP .Net 3 06-26-2003 01:02 PM
Re: bizaar exception that isn't really an exception jeff ASP .Net 0 06-24-2003 12:46 PM



Advertisments