Skip to content

Latest commit

 

History

History
44 lines (29 loc) · 1.61 KB

File metadata and controls

44 lines (29 loc) · 1.61 KB

Extra practical : Debugging a buggy code

In this exercise, you are asked to correct a code which doesn't work correctly. In particular, you'll have to address to types of bugs

  • Compilation/Execution bugs: those bugs throw errors called Exceptions and stop the code execution.
  • Semantic bugs: more difficult to handle, the code is running without throwing any execption but it doesn't output what you expected.

In both case, you may need to use the debugger to help you to troubleshoot the code.

Instructions

The code contains 3 bugs.

  1. The first thing to do is to understand you the code is supposed to do. You can read the class description, the comment in the code... If, for a given input, you know what it is supposed to output (i.e. expected outputs), try also to compare both real and expected outputs.

  2. Run the code

  3. Have a look to the exception and analyze it. What is the message ? What lines of your code are involved in that exception ? Does the message make sense with the involved lines ?

  4. Think about what could be the cause of this issue. You can use the debugger to help you

  5. Correct the bug and test you code again. Does it solve the problem ? Does it introduce a new problem ?

  6. When you found a decent fix, commit changes.

Note: the debugger can be very helpful but sometimes it will not be enough. You can also try to google the exception and/or the issue you are facing. You will certainly find someone who already experienced such issue.

Expected outputs of the code