bool IsQueryRunOK = false;

IsQueryRunOK is set to false by default :)
On Mon, Sep 14, 2009 at 12:41 PM, Processor Devil <[email protected]
> wrote:

> Well, it depends on situation...
> If there is exception, the IsQueryRunOK isn't set and it will return null
> (not so good), so you should specify IsQueryRunOK as false on the end of
> exception handle :)
>
> 2009/9/14 Subrato <[email protected]>
>
>
>> You should put that return statement in finally block that would help you
>> to return no matter what the situation.
>>  (I am answering this without actually running or debugging the code so
>> excuse me if that doesn't help)
>>
>>
>> On Sep 13, 2009, at 10:25 PM, Benj Nunez <[email protected]> wrote:
>>
>>
>>> Hello everyone,
>>>
>>> This has been nagging me for quite some time now, perhaps you can
>>> enlighten me on this.
>>> You see I have a function that returns either true or false. But what
>>> will happen if underneath
>>> this function, there's a call that would raise an exception?
>>>
>>>
>>>
>>>      public bool runQueryEx(String AQueryString)
>>>       {
>>>           bool IsQueryRunOK = false;
>>>
>>>           using (OleDbCommand cmd = new OleDbCommand(AQueryString,
>>> oleconn))
>>>           {
>>>               cmd.CommandType = CommandType.Text;
>>>
>>>               try
>>>               {
>>>                   cmd.ExecuteNonQuery();
>>>                   IsQueryRunOK = true;
>>>               }
>>>               catch (System.InvalidOperationException)
>>>               {
>>>                   //MessageBox.Show(ioe.Message, "Error",
>>>                   //    MessageBoxButtons.OK, MessageBoxIcon.Error);
>>>                   throw;
>>>               }
>>>               catch (System.Exception)
>>>               {
>>>                   //MessageBox.Show(e.Message, "Error",
>>>                   //    MessageBoxButtons.OK, MessageBoxIcon.Error);
>>>                   throw;
>>>               }
>>>           }
>>>
>>>           return IsQueryRunOK;     // will it return false in case
>>> of exception ?
>>>       }
>>>
>>>
>>> When debugging, I noticed that the last line:
>>>
>>>           return IsQueryRunOK;
>>>
>>>
>>> seems to get skipped *whenever* there's an exception. Is this normal?
>>> Is it implied
>>> that since it's a function it should return a value? Or just to be
>>> safe (and for peace of mind),  should I use a finally block? What
>>> would you recommend?
>>>
>>>
>>>
>>>
>>> Benj
>>>
>>>
>>>
>>>
>

Reply via email to