Chapter 13: Exeptions

Cards (23)

  • What is the main topic of Chapter 13?
    Exceptions in programming
  • Why might exceptional situations occur in a program?
    Due to complex program requirements
  • How do programmers view exceptional situations?
    As exceptions needing solutions
  • What does C# provide for handling exceptions?
    A complete exception infrastructure
  • Why do game developers advise against using exception handlers?
    Because exception handling is slow
  • What is the preferred behavior when exceptions occur in programs according to the text?
    To handle exceptions gracefully
  • What happens when a float is divided by zero?
    It results in Infinity
  • What does the compiler do when it detects an int division by zero?
    Flags it as an error
  • What exception is thrown when an int is divided by zero?
    System.DivideByZeroException
  • What does Visual Studio do when an exception occurs during execution?
    Catches the exception and shows a dialog
  • What are the steps to catch an exception in C#?
    • Encapsulate code in a try block
    • Match exceptions with catch clauses
    • Execute the first matching catch clause
    • Execute finally block if present
  • What is the purpose of a try block in exception handling?
    To encapsulate code that may throw exceptions
  • What happens if no matching catch clause is found?
    The exception is passed to the calling method
  • What must thrown exceptions contain?
    Information describing the exception
  • What class do all exceptions in C# inherit from?
    System.Exception
  • What happens when an exception is thrown and not caught?
    The method halts and passes the exception
  • What is the role of a finally block in exception handling?
    To execute code regardless of exception occurrence
  • How can finer selection of exceptions be achieved in C#?
    By using when clauses in catch clauses
  • 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 after try/catch
    • Throwing exceptions: indicates an error condition
  • What is the difference between errors and exceptions in programming?
    Errors are fatal, exceptions are manageable
  • What happens to the execution of a method when an exception is thrown?
    The method halts and passes the exception
  • Why is the order of catch clauses important?
    Because the first matching clause is executed
  • Can custom exception classes be defined in C#?
    Yes, they can inherit from System.Exception