exception_quiz - brainchildservices/curriculum GitHub Wiki

  1. What is c# Exceptions ?

    When executing C# code, different errors can occur: coding errors made by the programmer, errors due to wrong input, or other unforeseeable things. When an error occurs, C# will normally stop and generate an error message. The technical term for this is: C# will throw an exception (throw an error).

  2. What are the Common Exception ?

    • IndexOutOfRangeException
    • NullReferenceException
    • DivideByZeroException
  3. What is Exception Classes in C# ?

    The exception classes in C# are mainly directly or indirectly derived from the System.Exception class. Some of the exception classes derived from the System.Exception class are the System.ApplicationException and System.SystemException classes.

  4. What is Unhandled Exception ?

    If our program is not prepared to handle any kind of exception that it might run into, it would lead to the program crashing and prevent running of the rest of the program.

  5. Why we use Try-Catch ?

    We used a try - catch block to make the program work. If any exception occurs in the try block, the control will move to the catch block and then the statements after the catch block. However, the result that we get is not correct and we are not aware of what caused the exception any longer. try-catch shouldn't be used to just skip the exceptions but to make sure that we are aware of the cause that leads to the exception.

  6. What is the base class from which all the exceptions are derived ?

    System.Exception

  7. What is the difference between throw and throw ex ?

    throw statement preserves original error stack information but in throw ex, stack error of exception will be replaced with a stack trace starting with rethrow point.

  8. Which of the following statements applies to the situation where Exception is not handled in the program:

    • The Compiler will not allow the program to run the code.
    • CLR will terminate the program execution at the point where it encounters an exception.
    • CLR will not show any output. However, the code will execute successfully.
    • The Code executes successfully, and an error message gets printed.

    CLR will terminate the program execution at the point where it encounters an exception.

  9. Which of the following keyword can be used to rethrow an exception in C#:

    • return
    • throw
    • re-throw
    • create

    throw

  10. Does finally get executed if the code throws an error ?

    Finally is always executed.

⚠️ **GitHub.com Fallback** ⚠️