www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/05/30/07:47:23

From: epthecoder AT aol DOT com (EPTheCoder)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: try, throw, catch & const
Lines: 25
Message-ID: <1998053011311501.HAA09028@ladder03.news.aol.com>
NNTP-Posting-Host: ladder03.news.aol.com
Date: 30 May 1998 11:31:15 GMT
Organization: AOL http://www.aol.com
References: <356F7485 DOT 2F71 AT banet DOT net>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Since C++ is a strongly typed language, unlike C, the compiler
considers
     const char *
and
     char *
different types, though there is an obvious relationship to humans.
Therefore, if you throw one type, a handler of the other type
cannot catch it. I believe djgpp considers the type of the string
"unable to catch" to be char *, which explains the problem.

If you want to use a const char* handler, you might have to cast the
string to a const before throwing it.

An alternate route is not to throw the string directly at all. Create a simple
class with only a public pointer to the error string and throw that. Or, make
it more robust.

Hope this helped.



--
Evan
EPTheCoder AT aol DOT com          http://members.aol.com/EPTheCoder/
EPTheCoder AT bigfoot DOT com      http://bounce.to/EPTheCoder/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019