Exceptions Flashcards

1
Q

What are the 4 Policies for Handling Runtime Errors?

A
  1. Resumption
  2. Error rolling
  3. Long jumps
  4. Exceptions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the meaning of Resumption error handling policy?

A

On error, the offending command is retried.

Common methodology: invoke a “handler”; retry after the handler is done.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the meaning of Error rolling error handling policy?

A

Function indicates success or failure via its return value.

Caller should properly handle errors.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

?How is Longjump policy implemented in C

A

The function setjmp() marks the current code location as “come here if something wrong happens”. (returns 0)
The function longjmp() jumps to the error handling code. (returns error code)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Pros and cons of resumption policy?

A

Pros:
1. The offending command is not aware of the problem nor of the solution (blissful programming)

Cons:

  1. Perplexing Situation: You need the context to deal with the error, but you don’t have it.
  2. Hardly Ever Works: In most cases, the handler can try, but cannot promise, to fix the problem.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Error rolling pros and cons

A

Pros:

  1. Full flexibility
  2. Can choose to ignore errors

Cons:
1. Heavy responsibility on the programmers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Long jumps Pros and Cons

A
Pros:
1. Error-flagging code does not clutter logic flow
2. No need for lots of nested ifs
Cons: 
3. Painfully unsafe
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

?What does catch or declare means in Java

A

every exception that can arise needs to be catched or added to the method type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why finally clause is useful in a try block?

A
  1. for managing allocated resources

2. because the handlers may throw exceptions themselves

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does RAII means?

A

Resource Acquisition Is Initialization.

Acquire on initialization, release on destruction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the purpose of the ‘using’ keyword in C#?

A

RAII is inappropriate for garbage-collected languages.
Instead C# uses the keyword using:
using (StreamReader input = new StreamReader(“from.txt”))

from.txt will be closed on destruction of input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly