Debuggin & Defensive Programming

HideShow resource information
  • Created by: wreje035
  • Created on: 13-10-18 23:06
What is a bug?
When a piece of software does something unexpected when executing. Eg - incorrect output, incorrect processing, error messages or stack traces, the program crashes.
1 of 18
Why is debugging difficult?
Symptoms arent always obviously connected to the code that causes the bug. Could be many layers deep. Users are terrible at reporting bugs. You need a good understanding of the application domain, system design and libraries and frameworks to debug
2 of 18
Tools and techniques to aid with debugging?
Exception handling. Find and analyse probs when the occur - stack trace, profiling, rubber duck, dependecy injection. Also proactively trying to avoid problems - code analysis, defensive programming, automated testing
3 of 18
What is an exception?
Any deviation from expected system behaviour: eg div by 0, file not found, null variable (uninitialised), no such customer
4 of 18
Exception example - writing to a file. What could go wrong?
file doesnt exist, program doesnt have permission to write (read only), file is locked by another process, file is read only, not enough disk space
5 of 18
Options for handling exceptions
Try catch - the codes cleaner and there is clear seperation between 'real' code and error handling code.
6 of 18
When to catch?
Is there something useful we can do with the exception? Exceptions usually caused by 3 things: Bugs in the code - catch exception and log stack trace. User input error - catch and use it to tell the user what they did wrong
7 of 18
When to throw
I/O operations - network, database, file etc. Not much we can do so throw exception up to GUI
8 of 18
Exception filtering
multiple catch blcoks for a single try - only makes sense if you need different recovery for different exception types
9 of 18
Checked exceptions vs runtime exceptionsq
Checked extend excpeption, runtime extend runtimeexception - not forced to deal with runtime ones.
10 of 18
What is a stack trace?
Description of the execution path the program took leading up to an exception being thrown. Useful! Contain the exception thrown, chain of method calls leading up, name class package of method that threw except, message why
11 of 18
Display stack trace?
ex.printStackTrace or use a logger to record error - try catch logger.log ...
12 of 18
What is an interactive debugger?
Useful if you cant find the bug by inspection. enables you to stop the program at a point (break point), execute the program one line at a time (stepping) examine state of all variables and fields in the application
13 of 18
Rubber Duck debugging?
Explain problem to an inanimate object - forces you to think about the problem in more detail and with more structure, leading you to figure the prblem out when explaining
14 of 18
What is a profiler?
Shows information about what happend while the program was running. Useful for finding performance bottlenecks. Some can create UML sequence diagrams to help visualise.
15 of 18
What is code analysis?
Code analysers check source code for common errors and/or adherence to good practice. Some calculate the complexity of your code.
16 of 18
What is defensive programming?
Pay attention - read compiler and IDE warnings. Write and test in manageable chunks. Dont press on with additional features if you cant test the ones you already have. Always deal with caught exceptions.
17 of 18
Defensive programming
Write clean maintainable code! Stick to conventions, use brackets, encapsulate, document your APIs.
18 of 18

Other cards in this set

Card 2

Front

Why is debugging difficult?

Back

Symptoms arent always obviously connected to the code that causes the bug. Could be many layers deep. Users are terrible at reporting bugs. You need a good understanding of the application domain, system design and libraries and frameworks to debug

Card 3

Front

Tools and techniques to aid with debugging?

Back

Preview of the front of card 3

Card 4

Front

What is an exception?

Back

Preview of the front of card 4

Card 5

Front

Exception example - writing to a file. What could go wrong?

Back

Preview of the front of card 5
View more cards

Comments

No comments have yet been made

Similar Computing resources:

See all Computing resources »See all Debugging resources »