Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Exceptions in sepple

Name: Anonymous 2009-08-28 17:44

How do you manage exceptions in sepple? I experimented this some time ago. I thought it was a good pattern, but it led me to death:


#include <exception>
#include <string>
using namespace std;

/* This one is used for exceptions in memory management */
class MemoryException : public exception {
   private:
     string error;
   public:
     const char *what() {
       return error.c_str()
     }
     virtual ~MemoryException() throw() {};
     MemoryException &setError(string e) {
       error = e;
       return *this;
     }
};


Used as follows:

class HowAreYou {
  private:
    MemoryException error;
  public:
    void some_failing_method() throw (MemoryException) {
      throw error.setError("Oh, crap, I failed!");
    }
}


What do you think about it?

Name: Anonymous 2009-08-29 6:17

>>6
Oh, come on Anonymous... Are you telling me that when you was younger and noticed that your code was sucky you kept writing code in the same way? Are you telling me that when you discovered a new way of programming (e.g. callbacks) you didn't say "well, this may be useful"?

I agree on your point if we talk about languages: a poor language requires more design patterns in order to a void language suckyness (and this is expecially true for C++, where IMHO you should avoid references if you can).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List