CString.ReverseFind() and throw

in the help of CString.ReverseFind(), it says

int ReverseFind(
   XCHAR ch
) const throw();

what is this throw? if it is throwing an exception, how to catch it? thanks. 

WJ

0
WJ4113 (23)
7/9/2007 9:48:02 PM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies
1445 Views

Similar Articles

[PageSpeed] 7

On Mon, 9 Jul 2007 14:48:02 -0700, WJ <WJ@discussions.microsoft.com> wrote:

>in the help of CString.ReverseFind(), it says
>
>int ReverseFind(
>   XCHAR ch
>) const throw();
>
>what is this throw? if it is throwing an exception, how to catch it? thanks. 
>
>WJ

See:

Exception Specifications
http://msdn2.microsoft.com/en-us/library/wfa0edys(VS.80).aspx

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2498)
7/9/2007 9:57:31 PM
try {
    int i = cs.ReverseFind('x');
}
catch(...) {
    // something bad happened
}

So far as I know it only throws an exception for memory allocation errors 
and I've never had that happen.  It returns -1 if it can't find the char or 
string.

Tom

"WJ" <WJ@discussions.microsoft.com> wrote in message 
news:9AB75547-D1F0-4399-9687-FCC1E66C200D@microsoft.com...
> in the help of CString.ReverseFind(), it says
>
> int ReverseFind(
>   XCHAR ch
> ) const throw();
>
> what is this throw? if it is throwing an exception, how to catch it? 
> thanks.
>
> WJ
> 

0
tom.nospam (3240)
7/9/2007 10:12:07 PM
I guess that's why I've never seen it throw an exception.... :o)

Tom

"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message 
news:vlb593hk54fh4e0gdobe604c92558k60ob@4ax.com...
> On Mon, 9 Jul 2007 14:48:02 -0700, WJ <WJ@discussions.microsoft.com> 
> wrote:
>
>>in the help of CString.ReverseFind(), it says
>>
>>int ReverseFind(
>>   XCHAR ch
>>) const throw();
>>
>>what is this throw? if it is throwing an exception, how to catch it? 
>>thanks.
>>
>>WJ
>
> See:
>
> Exception Specifications
> http://msdn2.microsoft.com/en-us/library/wfa0edys(VS.80).aspx
>
> -- 
> Doug Harrison
> Visual C++ MVP 

0
tom.nospam (3240)
7/9/2007 10:13:36 PM
On Mon, 9 Jul 2007 15:12:07 -0700, "Tom Serface" <tom.nospam@camaswood.com>
wrote:

>try {
>    int i = cs.ReverseFind('x');
>}
>catch(...) {
>    // something bad happened
>}
>
>So far as I know it only throws an exception for memory allocation errors 
>and I've never had that happen.  It returns -1 if it can't find the char or 
>string.
>
>Tom

I can't imagine ReverseFind throwing any kind of C++ exception. If it were
possible, it would be an MFC exception, and it would be better to use:

   catch (CException* p)

The "throw()" decoration is equivalent to __declspec(nothrow) in the VC++
non-standard scheme of things, which means (a) it doesn't throw an
exception, and (b) if it does, it would be a really bad mistake, because
the compiler has compiled the function as if it cannot throw.

-- 
Doug Harrison
Visual C++ MVP
0
dsh (2498)
7/10/2007 12:43:22 AM
Yeah I figured that out from your subsequent post.  I was thinking of a 
CString knock-off that does throw exceptions and I read the code too 
quickly.  Apologies.

Tom

"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message 
news:g7l593psvee08t8oisutlpgdhdmcol7es8@4ax.com...

> I can't imagine ReverseFind throwing any kind of C++ exception. If it were
> possible, it would be an MFC exception, and it would be better to use:
>
>   catch (CException* p)
>
> The "throw()" decoration is equivalent to __declspec(nothrow) in the VC++
> non-standard scheme of things, which means (a) it doesn't throw an
> exception, and (b) if it does, it would be a really bad mistake, because
> the compiler has compiled the function as if it cannot throw.
>
> -- 
> Doug Harrison
> Visual C++ MVP 

0
tom.nospam (3240)
7/10/2007 2:02:16 AM
Reply:

Similar Artilces:

sending CString to CStatic label control from worker thread
I need to send a CString from a thread to a static label on the main dialog form. I think I have the thread working okay, but I am unsure how to send the CString to the dialog control. I have seen information on using PostMessage and SendMessage, but I don't really understand how to use these functions. Obviously I can't do like I tried below and I can't get a pointer to the control from the thread function, so just how do I say send the word "hello" to the SetWindowText() function of the label control on the dialog form. I have looked on the Internet and in se...

CString
How can I covert argv[0] to LPCSTR? Hi, Shouldn't CString(argv[0]) do the trick? Sander Verhagen [ Verhagen@nonono.Sander.com ] "Oliver Young" <please@no.spam.com> wrote in message news:er3JuEogDHA.616@TK2MSFTNGP11.phx.gbl... > > How can I covert argv[0] to LPCSTR? > > > Shouldn't CString(argv[0]) do the trick? OK. And how can I convert CString into LPCSTR? I need LPCSTR. I need to convert from char** ( argv[0] ) into LPCSTR. Please, forget CString, and MFC if possible. > How can I covert argv[0] to LPCSTR? LPCSTR...

std::string vs Cstring
Hello, I have recently been encouraged to utilise String classes, as opposed to C type char arrays due to some difficulty debugging some buffer overflows. I have looked into std::string and CString, but what are the benefits and drawbacks? The main problem I have is that I do a lot of data formatting using sprintf, for which I see no substitute using std::string, - MR On Thu, 30 Dec 2004 23:25:21 -0000, "Mark Randall" <strike@rapiercom.freeserve.co.uk> wrote: >Hello, > >I have recently been encouraged to utilise String classes, as opposed to C >type cha...

CString (again)
I have a class: class TestClass{ public: TestClass(){}; virtual ~TestClass(){}; BOOL CalcArea(double * pArea); void ReversePoints(); void OrderFromLowest(); std::vector<CoordinateClass> Pts; double OrientationType; BOOL XFlip; BOOL YFlip; double LTilt; double RTilt; double Buffer; int Style; CString Name; }; Now when I go like this: TestClass * pNew = new TestClass; pNew->Name = "anything in here will cause an error"; At runtime i get an unhandled exception which is comign from CString::AssignCopy() How do i fix this? Can't seem to reproduce this ...

How to covert CString to TCHAR and CString to LPCWSTR?
How to covert CString to TCHAR and CString to LPCWSTR? Where can I read about this? See my essay on CStrings on my MVP Tips site. joe On Mon, 30 Jun 2003 04:33:56 -0700, "julych" <julych@msn.com> wrote: >How to covert CString to TCHAR and CString to LPCWSTR? >Where can I read about this? Joseph M. Newcomer [MVP] email: newcomer@flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm ...

How to convert a BSTR to CString ??
I'm sure I'm missing something easy but..... How does one convert a BSTR to a CString? More specifically, I am processing the returned VARIANT value from an ActiveX control and it's value is a BSTR that I would like to move to a CString. Thanks in advance for your help. Bob Curry BSTR bstrValue; CString szValue; szValue = (LPCWSTR)bstrValue; Sreeram. Bob Curry wrote: > I'm sure I'm missing something easy but..... How does one convert a BSTR > to a CString? More specifically, I am processing the returned VARIANT value > from an ActiveX control and it...

CString...
What is the maximum characters a CString variable can hold? Is there anyway to increase a CString variables capacity to hold more characters? Thanks, RABMissouri As all index and length parameters are int variables, and there is no checking on assignment, the limit would be 2147483647 on a 32bit machine. If that's not big enough, rethink what you're doing. Jase "RBert" <drbert@microcore.net> wrote in message news:OB24du6FEHA.2308@tk2msftngp13.phx.gbl... > What is the maximum characters a CString variable can hold? Is there anyway > to increase a CString va...

CString in DLL
When I try to use CString in an MFC DLL, it gives the following error: error LNK2019: unresolved external symbol "public: __thiscall CString::~CString(void)" (??1CString@@QAE@XZ) referenced in function "public: virtual int __thiscall CMfcDllApp::InitInstance(void)" (?InitInstance@CMfcDllApp@@UAEHXZ) How can I use CString? Forgot to mention that the Env used is VC++ .NET "ajd" <ajaydhar@hotmail.com> wrote in message news:eLGoiPFMEHA.2388@TK2MSFTNGP09.phx.gbl... > When I try to use CString in an MFC DLL, it gives the following error: > > error L...

Array of CString s vs. CString Array
Hi all What's the deal with CStringArray? I have used CStringArray in several places but now I'm wondering why can't I use an array of CStrings instead - at least I wouldn't have to bother with SetSize(). TIA Richard C You can use whatever you like. CStringArray has been part of MFC before vector other STL collection became a part of C++. I'd use vector<CString>. -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo.com "Richard C" <rc@replytogroup.com> wrote in message news:tN97h.67412$rP1.57615@news-server.bigpond.net.au... > Hi all > > What&...

Are there any function like ReplaceNoCase for CString?
I can only find CString::Replace, but I need a function like ReplaceNoCase You are correct. Replace is case sensitive. You could convert the string to all upper or lower case first, but then your resulting string would be changed as well. You could also derive your own class from CString and add the new functionality to it. Tom <flyingxu@gmail.com> wrote in message news:1145000483.010766.64070@t31g2000cwb.googlegroups.com... >I can only find CString::Replace, but I need a function like > ReplaceNoCase > ...

Issue with casting CString to LPARAM and recasting it to CString...
Hi, I have developed a custom control with some customizations of the List Control class of MFC (CListCtrl). I have another custom class (MyItem) which is inherited from CItem. Each and every entry in the list control is a MyItem. Every time a new item is added into the LIst control we use the logic of maintaining a unique sequence number which is a CString and member of MyItem class. Here goes the implementation of the 2 main members of MyItem class void MyItem::SetListItemSequence(const CString& seq) { m_sequence = seq; } This member sets the newly added entries sequence value into ...

CString ?
One mine user reported strange error using my DLL. After analizing, the only way error could be mine is if this peace of code is wrong: BSTR p1; hr = pMyCOMObj->get_someProperty(&p1); CString cP1(p1); prop.someProperty = (LPCSTR)cP1; This peace of code is inside of my COM object. "prop" is C-type structure. "someProperty" is "const char*". I'm not working with very long strings. The CString cP1 seems to be a temporary stack object that'll get destroyed when it goes out of scope thereby rendering the pointer passed to prop.someProp...

CString to std::string
Hi, How to convert from CString to stl string? I tried many things and doesn't work. thanks CString Temp = "This is a test"; string Str = (LPCSTR)Temp; AliR. "Derek" <der@yahoo.com> wrote in message news:egz$UubMGHA.3728@tk2msftngp13.phx.gbl... > Hi, > How to convert from CString to stl string? > I tried many things and doesn't work. > thanks > > that I tried, doesn't work. "AliR" <AliR@online.nospam> wrote in message news:jstIf.20753$_S7.12727@newssvr14.news.prodigy.com... > CString Temp = "This is a t...

inherit from CString
I'd like to make a new class that inherits from CString and adds a few new string manipulation functions as well as some other member variables. For constructors, I'd like to simply use the CString constructors and add only my initialization values for my new member variables. Considering that there are multiple constructors for CString, what is an easy way to do this? (I'm a VC++ hobbyist, not a pro). I'd like to avoid having to write separate constructors to match each of the ones for CString. Thanks, Matt -- Remove Xs from address to reply via e-mail. Matt Roos wrot...

Throw Exception from a dll
Hi, I have got a problem then throwing exception from a dll and catch it in the exe. It is work to catch the object but then it leave the catch area and the object it being destroyed the program crach. What I have understood is that a dll and exe have different heaps and that is the problem. Can someone help me? How can a throw exception from a dll to the exe? /Mats Most likely you are using static linking in one or both of the components. Do not use static linking. Then you will have one heap. joe On Wed, 5 Nov 2003 00:47:55 -0800, <gnms71@hotmail.com> wrote: >Hi, I h...

CString hex value to CString decimal value
Please bare with me, I am quite new to C++. A CString contains a (large) hexadecimal string value, this value needs to be converted to an decimal value, and then put back as a string into an other CString. Data example: hexadecimal: 93d2f666 = decimal 2480076390 I have googled and found a lot of solutions (hex string to int) but none of them returns the correct decimal value, I suspect that converting a large hex string to int does not work. So if someone could point me to the right direction or could suply a working sample, please do. TIA Alex Your not looking hard enough. ...

CString manipulation
Hi, I would like to replace \r\n, \n\r or \n by a <BR> in a CString. I have some methode to do it but they are not optimized. I am starting with that : for (int i = 0; i < strHtml.GetLength(); i++) { if (strHtml.GetAt(i) == '\r') { if (strHtml.GetAt(i + 1) == '\n') { strHtml = strHtml.Mid(i, 2); strHtml.Insert(i, _T("<BR>")); } } else if (strHtml.GetAt(i) == '\n') { if (strHtml.GetAt(i + 1) == '\r') { strHtml = strHtml.Mid(i, 2); strHtml.Insert(i, _T("<BR>")); } else ...

CString =
I have traced one of my problems to running my dll in release mode and the exe in debug mode and calling a function in the exe from the dll that copies (I thought) a CString into an array of CStrings in the exe. The problem occors when the exe releases the dll and later deletes the array. The CString data is not really copied as I thought but only the pointer to the original CString is saved in the new one and so the heap pointer is wrong when it is time to delete the second CString. So, how do I prevent this problem? Thanks, Ken >I have traced one of my problems to running my dll in r...

Unable to convert from ATL::CString to vector<CString>::iterator
Hi Guys, I am going through the lengthy process of upgrading from a VS6 project to VS2005. The only issue I am left with is that I cannot work how to convert from a CString as part of an array to a vector iterator. The code is as follows vector<CString>::iterator ii = vector<CString>&(m_vsOverallAgentRetrievalQueueNames[i]); and the error message is as follows error C2440: 'initializing' : cannot convert from 'ATL::CStringT<BaseType,StringTraits> *' to 'std::_Vector_iterator<_Ty,_Alloc>' Can anyone help at all? Regards Tony &...

Is there a method in CString equivalent to std::string::replace?
Hi. How can I replace a substring in a CString? Isn't there an equvalent CString method? For example I can write: std::string s("C:\Temp\Some") s.replace(s.begin()+8, s.end(), "*.*", 3); After replacing 's' contains "C:\Temp\*.*"; How to implement this using 'CString'? Thanks in advance Martin No, 'CStringT::Replace' does quite a different thing: A snip from MSDN: int Replace( PCXSTR pszOld, PCXSTR pszNew ); int Replace( XCHAR chOld, XCHAR chNew ); This function replaces instances of the specified character or subs...

CString problem?
hello, CString str; str="hello wolrd"; how can i get first 4 letter of str? is there any function to get it? sorry i am new in visual c++ field, thanks halmuratov@gmail.com wrote: > hello, > > CString str; > str="hello wolrd"; > > how can i get first 4 letter of str? > > is there any function to get it? > > sorry i am new in visual c++ field, halmuratov: CString::Left(); You should be able to find this in the Help. If you know the name of the class, just look at the members (for CString in VS2002 and up you actually have to look...

string (clr) and CString (MFC) in same class
Is there any way to use both string (system.string) and CString in the same class? -- Tony H are you talking about System.String (as in .Net frameworks) or std::string? AliR. "Tony H" <TonyH@discussions.microsoft.com> wrote in message news:EAAFFBB3-C61B-4A88-97D3-AFD052AA8337@microsoft.com... > Is there any way to use both string (system.string) and CString in the same > class? > -- > Tony H > System::String, I think. I have to interface with a VB class in the same project which uses system.string. -- Tony H "AliR" wrote: > are you tal...

'CMap' of 'CString' to 'CString'
Hello! I'm trying to create a dictionary with both key and value of type 'CString'. I declare the object of 'CMap' so it is as closer to std::map, as possible: CMap<CString, const CString&, CString, const CString&> m_appLangs; and semantically it's like this: std::map<std::string, std::string> m_appLangs; But it seems 'CMap' is not realized as an RB-tree, I guess it must be realized through hash table. The problem is when I make the above declaration, my source file refuse to compile. Here is the simplified error message: cannot convert...

Is this a known issue? Call GetBuffer on CString, pass CString to a method prior to releasing the buffer...
....and you can't copy the CString in the called method (it copes nothing)? I have a method where I use a CString in place of a char buffer via CString::GetBuffer(4096) and if I pass it to my "log this value" method prior to calling CString::ReleaseBuffer() my logging method gets an empty string when adding CString together like this: l_csLog += in_csString; If I break in the called logging method, in_csString has the correct value in the watch window(s), but l_csLog always equals whatever it was before the concatenation. Now, if I call CString::ReleaseBuffer prior to th...

new XmlDataDocument(DataSet) throws exception
hi if i try to synchronize a dataset with xml using XmlDataDocument dataDoc = new XmlDataDocument(dataSetName) it throws an exception saying Object reference not set to an instance of the object. WHY? my dataset has 4 tables not related to each other in any way. please respond! ...