Lecture 3: Control Flow and Error Handling Flashcards
What is the difference between usual approach and event driven computing?
Usual: Start > hits well defined branch and loop points>Demand user inputs at points>proceeds to end> stops
Event driven computing: Start> set up complete > enter a main loop> loop around waiting for events then triggering code when they occur.
why use switch statements for flow control(3)?
- Simple, many frameworks allow you to write part of the code
- Switches are easy to extend
- Matching multiple events to one piece of code is easy
StackOverflowException
the call stack cannot grow any larger
OutOfMemoryException
the system has run out of memory
NullReferenceException
when an attempt is made to access an attribute/operation of an object when the reference is set to null
ArgumentException
one or more arguments were invalid
FileNotFoundException
specified file does not exist
InvalidCastException
a data type casting is not valid(usually because the types are unrelated)
DivideByZeroException
attempt made to divide by zero
IndexOutOfRangeException
array index is out of range
OverflowException
converting a value, such as with the Convert object, results in a loss of data
What are the Methods for error handling(2)?
Parse() and TryParse()
What are Exceptions?
- when an error is detected an object is created with information about the error
- object is thrown directly to the error handling routine
What are the three parts of a try catch finally block?
- try block contains code that may throw an exception
- catch blocks handle different exceptions that are thrown(0 or more)
- finally block executes the code regardless of exception or not
Why use a Custom Exception?
often the exception classes will not be suitable so we create our own.