Overriding the what() Method

Medium Exception Handling in OOP
Solve in Playground →

Problem Statement

Extend `std::exception` by creating a `CustomException` class. Override the `virtual const char* what() const noexcept` method to return `”Custom Error Occurred”`. Read an integer. If it equals `404`, throw the exception. Catch it and print `e.what()`.

Input Format

A single integer.

Output Format

Print the custom overridden message or 'OK'.

Constraints

None

Sample Input

404

Sample Output

Custom Error Occurred

Explanation

Overriding `what()` allows you to provide a specific string description for your custom exception when it is caught generically.

Starter Code

#include <iostream>
#include <exception>

class CustomException : public std::exception {
public:
    // Override what() here
};

int main() {
    // Implement logic and catch
    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