June 2025
Intermediate to advanced
1093 pages
33h 24m
English
What else can there be besides std::exception and everything that can be converted into it? In principle, you can use values of any type with throw. However, it is recommended to use the exception types from the standard library whenever possible.
If that is not possible, then use int, double, and string for throw.
// https://godbolt.org/z/67cd5bhhE#include <string>#include <iostream> // coutusing std::string; using std::to_string; using std::cout;void triggerError(int errorCase) { try { if(errorCase < 10) throw (int)errorCase; else if(errorCase < 20) throw 1.0/(errorCase-10.0); else throw string{"Error " + to_string(errorCase)}; } catch(int eval) { cout << "int-error: " << eval << "\n"; } catch(double eval) { cout ...
Read now
Unlock full access