Note that there are some explanatory texts on larger screens.

plurals
  1. POTry/Catch & Throw not working properly
    primarykey
    data
    text
    <p>I cannot seem to get my try/catch to work correctly. When you implement a try/catch, it's suppose to "throw" whatever string you told it to, right? And if you want, let the program continue on. Well mine does not say what I want it to say, nor does it continue, instead it tells me this then aborts:</p> <p>Debug Error!! Blah blah blah.exe R6010 -abort() has been called (Press Retry to debug the app)</p> <p>I want it to say: "You are trying to add more Items than are allowed. Don't. ", then continue on with the program. It's a LinkedList, it's not suppose to allow it to have more than 30 nodes. It does stop when it tries to add more than 30, just not how I want it to. I'm not sure what I'm doing wrong, help much appreciated!</p> <pre><code>Main: Collection&lt;int&gt; list; for(int count=0; count &lt; 31; count++) { try { list.addItem(count); cout &lt;&lt; count &lt;&lt; endl; } catch(string *exceptionString) { cout &lt;&lt; exceptionString; cout &lt;&lt; "Error"; } } cout &lt;&lt; "End of Program.\n"; Collection.h: template&lt;class T&gt; void Collection&lt;T&gt;::addItem(T num) { ListNode&lt;T&gt; *newNode; ListNode&lt;T&gt; *nodePtr; ListNode&lt;T&gt; *previousNode = NULL; const std::string throwStr = "You are trying to add more Items than are allowed. Don't. "; // If Collection has 30 Items, add no more. if(size == 30) { throw(throwStr); } else {}// Do nothing. // Allocate a new node and store num there. newNode = new ListNode&lt;T&gt;; newNode-&gt;item = num; ++size; // Rest of code for making new nodes/inserting in proper order // Placing position, etc etc. } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload