Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Question about exceptions in C++ via Xcode
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="cipher" data-source="post: 26723"><p>hi guys,</p><p> i'm currently working on my CS degree and have been using Visual C++. I just got an ibook and am using Xcode to create my applications. My question is about using exceptions in programs via Xcode. I created an application that includes some throw exception code in it. Whenever i try to compile and build in Xcode, I get a few errors returned to me. But when I try to compile and build the same exact code in Visual C++ it works perfectly. I was hoping someone could steer me in the right direction. I'll post the header files i'm using and the errors returned to me in this thread:</p><p></p><p>StackException.h file</p><p>#include <exception></p><p>#include <string></p><p>using namespace std;</p><p></p><p>class StackException: public exception //is this inheritance??</p><p>{</p><p></p><p>public:</p><p>StackException(const string &message=""): exception(message.c_str())</p><p>{</p><p></p><p>}</p><p>};</p><p>StackA.h file</p><p>#include "StackException.h"</p><p>typedef int StackItemType;</p><p>const int MAX_STACK = 20;</p><p></p><p>class Stack</p><p>{</p><p>public:</p><p>Stack();</p><p>bool isEmpty() const; </p><p>void push(StackItemType newItem) throw(StackException); </p><p>void pop() throw(StackException); </p><p>void pop(StackItemType &stackTop) throw(StackException); </p><p>void getTop(StackItemType &stackTop) const throw(StackException); </p><p></p><p>private:</p><p>char items[MAX_STACK];</p><p>int top;</p><p>};</p><p></p><p>Errors when I compile cpp files:</p><p>exception:55: error: std::exception::exception()</p><p>exception:53: error: candidates are: std::exception::exception(const std::exception&)</p><p>StackA.cpp:51: error: declaration of `void Stack::getTop(StackItemType&) const' throws different exceptions</p><p>StackA.cpp:27: error: declaration of `void Stack<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite9" alt=":eek:" title="Eek! :eek:" loading="lazy" data-shortname=":eek:" />p()' throws different exceptions</p><p>StackA.cpp:38: error: declaration of `void Stack<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite9" alt=":eek:" title="Eek! :eek:" loading="lazy" data-shortname=":eek:" />p(StackItemType&)' throws different exceptions</p><p>StackA.cpp:14: error: declaration of `void Stack:ush(int)' throws different exceptions</p><p>StackException.h:10: error: no matching function for call to `std::exception::exception(const char*)'</p><p>StackA.h:13: error: than previous declaration `void Stack::getTop(StackItemType&) const throw (StackException)'</p><p>StackA.h:11: error: than previous declaration `void Stack<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite9" alt=":eek:" title="Eek! :eek:" loading="lazy" data-shortname=":eek:" />p() throw (StackException)'</p><p>StackA.h:12: error: than previous declaration `void Stack<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite9" alt=":eek:" title="Eek! :eek:" loading="lazy" data-shortname=":eek:" />p(StackItemType&) throw (StackException)'</p><p>StackA.h:10: error: than previous declaration `void Stack:ush(int) throw (StackException)'</p><p></p><p>Thks....</p></blockquote><p></p>
[QUOTE="cipher, post: 26723"] hi guys, i'm currently working on my CS degree and have been using Visual C++. I just got an ibook and am using Xcode to create my applications. My question is about using exceptions in programs via Xcode. I created an application that includes some throw exception code in it. Whenever i try to compile and build in Xcode, I get a few errors returned to me. But when I try to compile and build the same exact code in Visual C++ it works perfectly. I was hoping someone could steer me in the right direction. I'll post the header files i'm using and the errors returned to me in this thread: StackException.h file #include <exception> #include <string> using namespace std; class StackException: public exception //is this inheritance?? { public: StackException(const string &message=""): exception(message.c_str()) { } }; StackA.h file #include "StackException.h" typedef int StackItemType; const int MAX_STACK = 20; class Stack { public: Stack(); bool isEmpty() const; void push(StackItemType newItem) throw(StackException); void pop() throw(StackException); void pop(StackItemType &stackTop) throw(StackException); void getTop(StackItemType &stackTop) const throw(StackException); private: char items[MAX_STACK]; int top; }; Errors when I compile cpp files: exception:55: error: std::exception::exception() exception:53: error: candidates are: std::exception::exception(const std::exception&) StackA.cpp:51: error: declaration of `void Stack::getTop(StackItemType&) const' throws different exceptions StackA.cpp:27: error: declaration of `void Stack:op()' throws different exceptions StackA.cpp:38: error: declaration of `void Stack:op(StackItemType&)' throws different exceptions StackA.cpp:14: error: declaration of `void Stack:ush(int)' throws different exceptions StackException.h:10: error: no matching function for call to `std::exception::exception(const char*)' StackA.h:13: error: than previous declaration `void Stack::getTop(StackItemType&) const throw (StackException)' StackA.h:11: error: than previous declaration `void Stack:op() throw (StackException)' StackA.h:12: error: than previous declaration `void Stack:op(StackItemType&) throw (StackException)' StackA.h:10: error: than previous declaration `void Stack:ush(int) throw (StackException)' Thks.... [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Question about exceptions in C++ via Xcode
Top