Content deleted Content added
Tag: Reverted |
Undid revision 1287318228 by 129.97.124.1 (talk) actually a bad idea, nvm |
||
Line 482:
<syntaxhighlight lang="cpp" line="1">
import std;
int main() {
try {
int i{vec.at(4)}; // Throws an exception, std::out_of_range (indexing for vec is from 0-3 not 1-4)
} catch (const
// An exception handler, catches std::out_of_range, which is thrown by vec.at(4)
std::println(stderr, "Accessing a non-existent element: {}", e.what());
} catch (const
// To catch any other standard library exceptions (they derive from std::exception)
std::println(stderr, "Exception thrown: {}", e.what());
|