Read an integer `code`. If it is `1`, throw the integer `404`. If `2`, throw the string literal `”String Error”`. If `3`, throw a `std::runtime_error(“Runtime Error”)`. Write three separate `catch` blocks to handle these exactly. Print ‘Caught Int: [val]’, ‘Caught String: [val]’, or ‘Caught Runtime: [e.what()]’.
A single integer code (1, 2, or 3).
Print the uniquely caught output.
Code will be 1, 2, or 3.
2
Caught String: String Error
C++ evaluates catch blocks sequentially. You can route different exception types to entirely different recovery workflows.
#include <iostream>
#include <stdexcept>
int main() {
int code;
if (std::cin >> code) {
try {
// Throw based on code
}
// Write multiple catch blocks here
}
return 0;
}Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used