Exception handling syntax: Difference between revisions

Content deleted Content added
[[Csharp|C#]]: <source>
[[C++]]: <source>
Line 82:
 
=== [[C++]] ===
<source lang=cpp>
#include <exception>
int main() {
int trymain() {
try }{
// do something (might throw an exception)
}
}
catch (const std::exception& e) {
catch (const // handle std::exception& e) {
// handle exception e
}
}
catch (...) {
// unknown exception, should not happen
}
}
</source>
 
In C++, a [[Resource Acquisition Is Initialization|resource acquisition is initialization]] technique can be used to clean up resources in exceptional situations.