C++ how do I do exception handling for switch case
<p>If user key in letter like "a" , it will result in endless loop, the default: doesnt work. </p>

<p>How do i do exception handling so its will output error message instead of endless loop.</p>

<p>Thanks!</p>

<p>Below is my code:</p>

<pre><code>done=false;
do
{
cout &lt;&lt; "Please select the department: " &lt;&lt; endl;
cout &lt;&lt; "1. Admin " &lt;&lt; endl;
cout &lt;&lt; "2. HR " &lt;&lt; endl;
cout &lt;&lt; "3. Normal " &lt;&lt; endl;
cout &lt;&lt; "4. Back to Main Menu " &lt;&lt; endl;
cout &lt;&lt; "Selection: ";
cin &gt;&gt; choice;



switch (choice) {
  case 1:
      department_selection = "admin";
    done=true;
    break;
  case 2:
      department_selection = "hr";
    done=true;
    break;
  case 3:
      department_selection = "normal";
    done=true;
    break;
  case 4:
      selection = "hr_menu";
    done=true;
    break;
  default:
    cout &lt;&lt; "Invalid selection - Please input 1 to 3 only.";
    done=false;
        }
}while(done!=true);
</code></pre>
