Chapter 17: Exceptions

Cards (13)

  • What does exceptional situations in programming refer to?
    Situations like file unavailability or division by zero
  • How does C# handle exceptions?
    C# provides a complete exception infrastructure
  • Why do game developers prefer programs to crash instead of using exception handlers?
    Exception handling is slow and can affect performance
  • What happens when an int division by zero occurs in C#?
    An exception is thrown, causing a crash
  • What is the purpose of a try block in exception handling?
    To encapsulate code that might throw an exception
  • What happens if no matching catch clause is found for an exception?
    The exception is passed to the calling method
  • What is the base class for all exceptions in C#?
    System.Exception
  • What is the role of a finally block in exception handling?
    It executes code regardless of exception occurrence
  • How does a when clause enhance exception handling?
    It allows finer filtering of caught exceptions
  • What happens if an exception occurs during a constructor execution?
    The exception is passed to the calling level
  • What does Unity do with unhandled exceptions?
    Logs them using a global try/catch construct
  • What are the key components of exception handling in C#?
    • try block: encapsulates code that may throw exceptions
    • catch clause: handles specific exceptions
    • finally block: executes code regardless of exceptions
    • throw statement: raises exceptions when needed
  • What are the steps involved in throwing and catching an exception in C#?
    1. Code execution leads to an exceptional situation.
    2. An exception is thrown using the throw statement.
    3. The method halts and looks for a matching catch clause.
    4. If found, the catch clause executes; if not, it propagates.
    5. Finally block executes if present.