Question

Let's say I have a setter which has the following possibilities:

  1. The setter assigns the value to a local variable (common use).
  2. The setter cannot assign the value to a local variable due to another condition which is determined at run time. The lack of assignment and the condition is considered normal operation for the application due to user decisions.
  3. The setter experiences an application error.

I'm debating on two solutions, wondering if there are any better ideas:

A. Using a status class to hold the result of #1 or #2, with a try/catch to indicate #3. B. Using a try/catch to indicate #2 or #3, with different classes indicating the difference between #2 and #3.

The problem I have with A is that every time there is a property assign, there needs to be a check of status.

The problem I have with B is that the try/catch seems as if it should be reserved for unexpected application errors, not an expected error due to user interaction.

I don't feel that there is a way to use the Proxy class.

Any opinions on A vs B, or other options? Also should mention I'm trying to avoid the use of event listeners.

Was it helpful?

Solution

Not 100% sure what you're trying to do, but if you're trying to get the result of calling a setter (to see what, of any, kind of error occurred), you can:

1) use events or signals to indicate a problem:

foo.addEventListener(MyEvents.APP_ERROR, this._handleError);
foo.setter = bar;

2) change the setter to be a function with a return value:

public function setFoo( bar:Bar ):ErrorType;

3) make use of a lastError property that gets set when there's a problem:

foo.setter = bar;
if( foo.lastError != ErrorType.NONE )
    // do something
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top