Quantcast

Maximum PC

It is currently Wed Apr 16, 2014 3:22 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: More C++ woes: Custom exceptions
PostPosted: Thu Mar 05, 2009 10:05 am 
Clawhammer
Clawhammer

Joined: Sun Jun 18, 2006 7:37 pm
Posts: 4535
I'm trying to make a custom exception as per specifications of this programming assignment. I'm still developing using Visual Studio (worked out the kinks of my last question) but I've tried some examples, integrated them into my project, but it gives me this "can't access" violation (I found out it's because the deleter goes nuts). This violation only occurs when I implement the example codes.

So here's my custom exception
Code:
class file_parse_exception
{
   public:
      file_parse_exception(string s) : message(s){}
      ~file_parse_exception() throw(){}

      const char* what() const throw(){return message.c_str();}

   private:
      string message;      
};


And every time I call it, that's when stuff hits the fan. I tried just with the constructor only, but if I throw it, I get an "unhandled exception" error.

Basically I have another class that does stuff, but it has to throw exceptions in the event something bad happens (like accessing an element in an array that's not there)

EDIT: On inspection, VS freaks out when I do the "file not found" exception. So here's my code segment for that:

Code:
   ifstream asm_code(file_name.c_str(),ios_base::in);

   if(!asm_code)
   {
      throw(file_parse_exception("Requested file not found."));
      buffer = new char[0];
      lines_code.clear();
   }


The buffer is a char *, I put that there because last I tried doing this, I got an error trying to delete it (this class's dtor deletes the buffer)


Top
  Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 10:55 am 
Clawhammer
Clawhammer

Joined: Sun Jun 18, 2006 7:37 pm
Posts: 4535
Hate to double post, but I was stupid.

You throw the exception AFTER everything else (that buffer = [0] wasn't being done so that's what caused problem).


Top
  Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 10:56 am 
Monkey Fed [PC]
Monkey Fed [PC]
User avatar

Joined: Wed Oct 05, 2005 7:53 pm
Posts: 7076
That's not a double post bro. It's good to let us know you found your problem.


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group