Inheriting from std::exception

Medium Exception Handling in OOP
Solve in Playground →

Problem Statement

Include “. Create a custom `MyException` class that publicly inherits from `std::exception`. Read a string. If the string is `”ERROR”`, throw `MyException`. In your catch block, catch it polymorphically as `const std::exception& e` and print ‘Standard Exception Caught’. Otherwise, print ‘Success’.

Input Format

A single word string.

Output Format

Print the catch result or success.

Constraints

None

Sample Input

ERROR

Sample Output

Standard Exception Caught

Explanation

Inheriting from `std::exception` makes your custom errors compatible with standard C++ library exception handling protocols.

Starter Code

#include <iostream>
#include <string>
#include <exception>

class MyException : public std::exception {
    // Empty class inheriting exception
};

int main() {
    // Read string, throw if ERROR, catch polymorphically
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

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