The SAMATE Project Department of Homeland Security
Downloads:  Selected

Back to the previous page...Back to the previous page

Test Case IDCandidate72
Bad / GoodBadBad test case
AuthorN/A
Associated test caseN/A
ContributorSecureSoftware
LanguageC++
Type of test caseSource Code
Input stringN/A
Expected OutputN/A
InstructionsN/A
Submission date2005-11-07
DescriptioniconWhen an exception is thrown and not caught, the process has given up an opportunity to decide if a given failure or event is worth a change in execution. (from TCCLASP-5_6_18_10)
Filename

There is no comments :: Submit a comment :: RSS

>./Uncaught_exception.cpp
  1. #include <iostream.h>
  2. #include <new>
  3. #include <stdlib.h>
  4. int
  5. main(){
  6. char input[100];
  7. int i, n;
  8. long *l;
  9. cout << "How many numbers do you want to type in? ";
  10. cin.getline(input, 100);
  11. i = atoi(input);
  12. //here we are purposly not checking to see if this call to
  13. //new works
  14. //try {
  15.         l = new long [i];
  16. //}
  17. //catch (bad_alloc & ba) {
  18. // cout << "Exception:" << endl;
  19. //}
  20. if (l == NULL)
  21.         exit(1);
  22. for (n = 0; n < i; n++) {
  23.         cout << "Enter number: ";
  24.         cin.getline(input, 100);
  25.         l[n] = atol(input);
  26. }
  27. cout << "You have entered: ";
  28. for (n = 0; n < i; n++)
  29.         cout << l[n] << ", ";
  30. delete[] l;
  31. return 0;
  32. }
  33.