Content deleted Content added
Tag: Reverted |
|||
Line 482:
<syntaxhighlight lang="cpp" line="1">
import std;
using Exception = std::exception;
using OutOfRangeException = std::out_of_range;
using Vector = std::vector;
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());
|