Click here to Skip to main content
15,884,472 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
AnswerRe: POS discount headache Pin
led mike6-Aug-07 4:57
led mike6-Aug-07 4:57 
GeneralRe: POS discount headache Pin
dazfuller6-Aug-07 5:23
dazfuller6-Aug-07 5:23 
AnswerRe: POS discount headache Pin
originSH6-Aug-07 5:00
originSH6-Aug-07 5:00 
GeneralRe: POS discount headache Pin
dazfuller6-Aug-07 5:33
dazfuller6-Aug-07 5:33 
GeneralRe: POS discount headache Pin
led mike6-Aug-07 8:42
led mike6-Aug-07 8:42 
GeneralRe: POS discount headache Pin
Robson Félix14-Aug-07 7:01
Robson Félix14-Aug-07 7:01 
AnswerRe: POS discount headache Pin
amit.arora14-Aug-07 4:58
amit.arora14-Aug-07 4:58 
QuestionError States Pin
Leslie Sanford5-Aug-07 17:15
Leslie Sanford5-Aug-07 17:15 
It's easy enough to throw an exception from a method in a class you've written when the preconditions of the method haven't been met. You can do so while maintaining the class's invariants. It's harder, though, handling an exception thrown in the middle of the method from a source outside your control, say from an object you've invoked a method on. Enforcing a class's invariants is trickier here.

One approach is to treat the exception as an event. When it occurs, you have code in place that transitions your object to a state appropriate to the exception thrown, i.e. some kind of error state. The question then becomes how should the object behave in an error state? Are there steps to be taken to bring the object back to a useable state? If so, what are they?

I'll give an example. I have a Synthesizer class in my C# Synth Toolkit. It's capable of recording the waveform output as it is synthesized and writing it to a wave file. This takes place on thread other than the main one.

Let's say that an IO exception of some sort happens when attempting to write the waveform data to file. The exception is caught. Now what? I was thinking that it would be appropriate to raise an event on the main thread notifying the user that an error occurred. In addition, the Synthesizer would transition back to a non-recording state. The Synthesizer would continue to function normally.

Another situation has me a bit stumped, though. The Synthesizer uses an OutputDevice class for playing waveform data. If the OutputDevice object being used throws an exception, it's pretty much a show stopper. There's not much the Synthesizer can do if it's OutputDevice isn't useable. So I was thinking that in this situation, an error state would be appropriate. In this state, some of its methods would throw an InvalidOperationException; they just can't be performed if the OutputDevice isn't working correctly. Other operations might be allowed in order to reset the OutputDevice to get it working or use a different one.

I guess what I'm getting at here is that I'm wondering how you deal with exceptions when they pretty much render an object unuseable.
AnswerRe: Error States Pin
Luc Pattyn5-Aug-07 22:52
sitebuilderLuc Pattyn5-Aug-07 22:52 
GeneralRe: Error States Pin
Leslie Sanford6-Aug-07 5:55
Leslie Sanford6-Aug-07 5:55 
GeneralRe: Error States Pin
Luc Pattyn6-Aug-07 6:23
sitebuilderLuc Pattyn6-Aug-07 6:23 
Questionencapsulation VS development time Pin
DynV2-Aug-07 14:13
DynV2-Aug-07 14:13 
AnswerRe: encapsulation VS development time Pin
led mike3-Aug-07 5:10
led mike3-Aug-07 5:10 
AnswerRe: encapsulation VS development time Pin
dazfuller6-Aug-07 5:38
dazfuller6-Aug-07 5:38 
QuestionRemove Quote from Writeline output Pin
rfrank535625-Jul-07 8:21
rfrank535625-Jul-07 8:21 
AnswerRe: Remove Quote from Writeline output Pin
..Hubert..26-Jul-07 3:38
..Hubert..26-Jul-07 3:38 
QuestionApplication framework for small or mid sized apps Pin
..Hubert..24-Jul-07 23:45
..Hubert..24-Jul-07 23:45 
AnswerRe: Application framework for small or mid sized apps Pin
drinkwater25-Jul-07 4:26
drinkwater25-Jul-07 4:26 
GeneralRe: Application framework for small or mid sized apps Pin
Dave Herren25-Jul-07 9:55
Dave Herren25-Jul-07 9:55 
GeneralRe: Application framework for small or mid sized apps Pin
..Hubert..25-Jul-07 22:24
..Hubert..25-Jul-07 22:24 
GeneralRe: Application framework for small or mid sized apps Pin
led mike3-Aug-07 5:03
led mike3-Aug-07 5:03 
GeneralRe: Application framework for small or mid sized apps Pin
..Hubert..3-Aug-07 5:38
..Hubert..3-Aug-07 5:38 
GeneralRe: Application framework for small or mid sized apps Pin
led mike3-Aug-07 7:02
led mike3-Aug-07 7:02 
AnswerRe: Application framework for small or mid sized apps Pin
awesomeo21-Aug-07 20:18
awesomeo21-Aug-07 20:18 
QuestionRecording a wave file Pin
Leslie Sanford21-Jul-07 16:35
Leslie Sanford21-Jul-07 16:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.