Create a base `AppError(Exception)`. Create two subclasses: `DatabaseError(AppError)` and `NetworkError(AppError)`. If the input is ‘DB’, raise `DatabaseError`. If ‘NET’, raise `NetworkError`. Catch them purely using the base `AppError` and print ‘AppError caught: [name of class]’.
A single string ('DB' or 'NET').Print the caught base exception.
None
DB
AppError caught: DatabaseError
A structured hierarchy allows you to catch broad categories of exceptions (AppError) while still retaining specific sub-type information.
class AppError(Exception): pass
# Define DatabaseError and NetworkError
if __name__ == '__main__':
err_type = input().strip()
# Raise specific error, catch with AppError
passEmbedded 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