Exception handling syntax: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Tags: Mobile edit Mobile app edit iOS app edit App section source
 
(2 intermediate revisions by one other user not shown)
Line 207:
try {
// do something (might throw an exception)
} catch (const std::runtime_error e) {
// handle a runtime_error e
} catch (const std::exception& e) {
// handlecatches exceptionall exceptions as e
} catch (...) {
// catches all exceptionsthrown types (including primitives or objects that do nit extend exception), not already caught by a catch block before
// can be used to catch exception of unknown or irrelevant type
}
}
Line 587 ⟶ 588:
} catch (error) {
// Statements that execute in the event of an exception
}
</syntaxhighlight>
 
=== Kotlin ===
{{Further|Kotlin (programming language)}}
<syntaxhighlight lang="kotlin">
try {
// Code that may throw an exception
} catch (e: SomeException) {
// Code for handling the exception
}
</syntaxhighlight>