French Boy
French Boy

Reputation: 1491

Unknown exception is thrown without inner exception?

The following exception:

Exception: An error occurred while executing the command definition.
See the inner exception for

and there is no inner exception.

Is thrown from the following code from the getter:

bool IsVerifyingPassword
{
    get
    {
        return (bool?)ViewState["IsDoubleCheckPassword"] ?? false;
    }
    set { ViewState["IsDoubleCheckPassword"] = value; }
}

Where's my fault?

Upvotes: 0

Views: 285

Answers (1)

sll
sll

Reputation: 62484

Try out:

bool IsVerifyingPassword
{
  get
  {
       bool returnValue = false;
       object viewStateValue = ViewState["IsDoubleCheckPassword"];           
       if (viewStateValue != null)
       {           
          // stay false if not able to retrieve bool from ViewState
          bool.TryParse(viewStateValue.ToString(), out returnValue);
       }

       return returnValue;
  }

If the property really should be nullable boolean then:

bool? IsVerifyingPassword
{
   get
   {
       object viewStateValue = ViewState["IsDoubleCheckPassword"];           
       if (viewStateValue != null)
       {
          bool returnValue = false;

          // stay false if not able to retrieve bool from ViewState
          bool.TryParse(viewStateValue.ToString(), out returnValue);
          return returnValue;
       }else
       {
          return null;
       } 
   }

Upvotes: 2

Related Questions