Skip to content

Instantly share code, notes, and snippets.

@camh96
Created June 9, 2014 07:39
Show Gist options
  • Save camh96/35c1b742a2fe3a561854 to your computer and use it in GitHub Desktop.
Save camh96/35c1b742a2fe3a561854 to your computer and use it in GitHub Desktop.
#include<iostream>
#include<vector>
int main()
try {
std::vector<int> vec{3,4,3,1};
int i{vec.at(4)};
}
//An exception handler, catches std::out_of_range
catch(std::out_of_range& e) {
std::cerr<<"Accessing a non-existent element: "<<e.what()<<'\n';
}
catch(std::exception& e) {
std::cerr<<"Exception thrown: "<<e.what()<<'\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment