Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
4003CEM-continued/lab_except.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
34 lines (29 sloc)
874 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "lab_except.h" | |
#include <iostream> | |
#include <vector> | |
int main() | |
{ | |
std::vector<int> ages { 1, 15, 17, 20, -999 }; | |
/* Notice that this is using the range based for loop syntax. | |
This means that the variable 'a' will become each of the values in | |
the ages vector. NOT an index value to each position in the vector. | |
*/ | |
for( const int a : ages ) | |
{ | |
try | |
{ | |
/* We are saving the result of you_are() to a temporary variable | |
because, if there is a problem calling you_are(). We want to | |
know before we starting outputting. | |
If we did not do this, then we might end up printing half a | |
sentance. */ | |
const std::string description = you_are( a ); | |
std::cout << "When you are " << a << " you are a " << description << std::endl; | |
} | |
catch( const std::invalid_argument& e ) | |
{ | |
std::cerr << e.what() << std::endl; | |
} | |
} | |
return 0; | |
} |