So, I am try to write a simple base Exception class for C++, based on the Java Exception class. I'm sure there are great libraries out there already, but I am doing this for practice, not production code, and I'm curious and always looking to learn. One of the things the Java's Exception does, which I would like to also implement, is the concept of a 'cause'. In Java, a new Exception with a cause looks like:
Exception cause = new Exception();
Exception newExcept = new Exception(cause);
However, in C++, passing an Exception as an argument to the constructor is how the copy constructor is called. So, there's the conceptual disconnect between copying the Exception and creating a new Exception with a cause. This isn't a problem in Java, obviously.
I guess I'm just wondering what the best way to handle this would be. A few ideas I had were:
- Differentiate with a dummy variable
- Just create new Exception, and called setCause() method
- Something like copy constructor is
Exception(Exception &)
and constructor with cause isException(Exception *)
Thanks