GoConqr has a new look! Let us know what you think.

Flashcards

Exception handling

a St George GCSE IT - Unit 1 GCSE English 11 cards

Cards in this deck (11)

  1. 1Why do we need to error trap in program code?No matter the programmer or the program, errors and mistakes can occur.
    If errors occur and they are not handled in the correct way then the program will crash which can have a massive detrimental effect.
  2. 2What are the three main types of errors you experience when programming?- Compilation errors
    - Runtime errors
    - Logical errors
  3. 3What is a Compilation error?Compilation errors, also known as compiler errors, are errors that prevent your program from running the program.
    When you press F5 to run a program, Visual Studio compiles your code into a binary language that the computer understands.
    If the Visual Studio compiler comes across code that it does not understand, it issues a compiler error.
    Most compiler errors are caused by mistakes that you make when typing codee.g. you might misspell a keyword, or leave out some necessary punctuation.
    Syntax errors: errors due to the fact that the syntax of the language is not respected.
    Semantic errors: errors due to an improper use of program statements.
  4. 4Give examples of Compilation errors.Example 1
    Displaying various syntax errors.
    - misspelling keywords
    Example 2
    Small semantic errors
    int x -= 1;
    int y += 1;
  5. 5What is a Runtime error?Run-time errors are errors that occur while your program runs. These typically occur when your program attempts an operation that is impossible to carry out.
    An example of this is division by zero. Suppose you had the following statement:
    Speed = Miles / Hours
    If the variable Hours has a value of 0, the division operation fails and causes a run-time error.
    The program must run in order for this error to be detected, and ifHours contains a valid value, it will not occur at all.
    When a run-time error does occur, you can use the debugging tools in Visual Studio to determine the cause.
  6. 6What is a logical error?Logic errors are errors that prevent your program from doing what you intended it to do.
    Your code may compile and run without error, but the result of an operation may produce a result that you did not expect e.g. you might have a variable named FirstName that is initially set to a blank string. Later in your program, you might concatenate FirstName with another variable named LastName to display a full name.
    If you forgot to assign a value to FirstName, only the last name would be displayed, not the full name as you intended.
    Logic errors are generally the hardest to find and fix, but again Visual Studio has debugging tools that make this job easier.
  7. 7What is an Exception?An Exception is an object delivered by the Exception class.
    Definition: exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions.
    Exceptions are used to avoid system failure in an unexpected manner.
    Exception handles the failure situation that may arise.
  8. 8What is an Unhanded Exception?If an exception is thrown and there is no handler to deal with the exception, this situation is called an Un-Handled exception situation.
    If the code is executed, the program will break and you will get an unhandled exception dialog.
    Code that is trying to convert a string to a number that contains a letter is an example of an exception. If it is not handled then the program will crash.
  9. 9Give examples of different Exceptions and explain why they are needed.There are all sorts of ways you can write code that C# doesn’t know how to deal with. It would be difficult to troubleshoot your problems if your program simply gave a generic error message.
    Therefore there are different types of Exceptions that occur.
    Examples exceptions include:
    Exception (Generic)
    NullReferenceException
    DivideByZeroException
    FormatException
    InvalidCastException
  10. 10How do we handle exceptions?In programs, we can implement ways to catch errors so they do not crash the program and one of the ways you can do this is by using a “Try Catch” block.
    To handle the exception, we need to place the code we want to happen within a try block.
    When an exception occurs inside the try block, the control looks for the catch block and raises an exception that is handled in the catch block e.g. outputting a message to say "you can only enter numeric values".
  11. 11Handler for Multiple ExceptionsTo handle multiple exceptions, you can place multiple catch blocks for a single try block.
    When an exception is thrown, the type of the exception is examined against each catch block and when a match occurs, the exception enters into the catch block and gets handled.

Information

Description
Flashcards for Exception Handling unit of the AS part of the SSD course by CCEA.
Created by
a St George · May 2022
Updated
May 27, 2022
Views
7
History
  • Created by Ruth Hyndman · Jan 5, 2016
  • Copied by a St George · May 26, 2022
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?