Identifying the try Block
In Python, which block is used to wrap code that may raise an exception?
- expect
- check
- attempt
- catch
- try
Purpose of the except Block
Which block handles the exception if one occurs in the corresponding try block?
- escape
- stop
- error
- handle
- except
Ordering of Code Blocks
Which of the following is the correct order for try, except, and finally blocks in Python?
- try – finally – except
- try – except – finally
- except – finally – try
- finally – try – except
- except – try – finally
Catching Multiple Exceptions
Which syntax allows you to catch multiple different exceptions with one except statement?
- except TypeError u0026 ValueError:
- except TypeError or ValueError:
- except (TypeError, ValueError):
- except [TypeError, ValueError]:
- except {TypeError, ValueError}:
Using finally for Cleanup
What is the purpose of the finally block in Python exception handling?
- To execute cleanup code regardless of exceptions
- To repeat the try block
- To catch all exceptions
- To terminate the program
- To skip code when exceptions occur
Raising an Exception
Which keyword is used to manually raise an exception in Python?
- create
- emit
- error
- throw
- raise
Catching All Exceptions
What type of exception will be caught by 'except Exception:' in Python?
- All errors including syntax errors
- Only runtime exceptions
- Any exception derived from Exception
- No exceptions
- Syntax errors
Custom Exception Definition
Which is the correct way to define a custom exception called MyError in Python?
- class MyError(Exception): pass
- def MyError(): Exception
- raise MyError(Exception): pass
- class MyError: Exception pass
- class MyError: raise Exception
Exception Message Retrieval
Given 'except Exception as e:', how can you access the error message?
- msg(e)
- e.message()
- e.getError()
- get_message(e)
- str(e)
Code Execution Flow
If an exception occurs in a try block and is caught, which following block is always executed?
- abort
- stop
- unless
- continue
- finally
Syntax Error Handling
Can 'except Exception:' catch a SyntaxError raised due to a typo in code?
- Only if using except SyntaxError
- Yes, it catches all errors
- Yes, if inside a try block
- Only if using except BaseException
- No, SyntaxError is not caught
Using else in try/except
What is the purpose of the else block in try/except/else statements in Python?
- To define cleanup code
- To rerun the try block
- To execute code if no exception occurs
- To ignore exceptions
- To always run before except
Accessing the Exception Name
Which option shows a valid way to print the type of an exception caught as 'e'?
- print(type(e))
- print(type of e)
- print(error(e))
- print(e.type)
- print(e.class)
Custom Exception Raising
How do you raise your custom exception defined as 'class MyError(Exception): pass'?
- MyError() raise
- raise new MyError()
- throw MyError()
- raise MyError()
- MyError.raise()
Handling ZeroDivisionError
Given 'x = 10 / 0', which exception type should be used to catch this error?
- ArithmeticErrorr
- OverflowError
- KeyError
- ZeroDivisionError
- ValueError