Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Exception handling

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Sat Jan 03, 2009 7:37 pm    Post subject: Exception handling Reply with quote

Code:
#include <iostream>
#include <string>

int main()
{
   try
   {
      throw std::string("Hello, World?!").c_str();
   }
   catch (const char *e)
   {
      std::cout << e << '\n';   // Output: Nothing.
      std::cout << ++e;         // Output: ello, World?!
   }

   std::cin.sync();
   std::cin.ignore();

   return 0;
}

Seems like the first character has been null terminated, but I'm not really sure why. Any thoughts?
Back to top
View user's profile Send private message
crayzbeef
Expert Cheater
Reputation: 0

Joined: 21 Jan 2007
Posts: 101

PostPosted: Sun Jan 04, 2009 3:32 pm    Post subject: Reply with quote

Maybe because you're throwing a string and catching a char?
Back to top
View user's profile Send private message
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Sun Jan 04, 2009 3:37 pm    Post subject: Reply with quote

Code:
   catch (string e)

_________________
What dosen't kill you, usually does the second time.
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Sun Jan 04, 2009 3:40 pm    Post subject: Reply with quote

That would be bizzare to check excpetion for.

Edit: instead of using sync and ignor to pause instant close, use cin.
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Mon Jan 05, 2009 6:30 am    Post subject: Reply with quote

crayzbeef wrote:
Maybe because you're throwing a string and catching a char?

He throws char*. (String.c_str())

That's pretty odd, but the problem is at c_str, since:
Code:
   try
   {
      throw "Hello, World!";
   }
   catch (const char *e)
   {
      std::cout << e << '\n';   // Output: Hello, World!
   }

Works perfectly fine.

You could also simply do:
Code:
   try
   {
      throw std::string("Hello, World!");
   }
   catch (std::string e)
   {
      std::cout << e.c_str() << '\n';
   }
Back to top
View user's profile Send private message
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Mon Jan 05, 2009 5:08 pm    Post subject: Reply with quote

@Rot1
This is just a test case, not my actual code. You're bizarre. Razz

@HornyAZNBoy, Symbol
Yea that is my current approach, though it would be nifty to throw a c string.

My best guess is that throw creates a copy of the char pointer (points to an internal buffer of string), which is then being cleaned up by the string object since it is no longer in use. If the string is defined outside the try block it works as you'd expect. D'oh.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites