From: JoeC on
I have read some on exception handling but I never really understood
it or how to use it. Now I am running into problems using an array.
I have tracked my bugs to this line. I want to see what the problem
is.

Is this correct?

if((num > 255) || (num < 0)){

return;
}

try{
bits[num] = col; <--

}
catch (char * str){
MessageBox(NULL, str, "Info", MB_OK);
}
From: Ian Collins on
On 04/ 1/10 01:39 PM, JoeC wrote:
> I have read some on exception handling but I never really understood
> it or how to use it. Now I am running into problems using an array.
> I have tracked my bugs to this line. I want to see what the problem
> is.
>
> Is this correct?
>
> if((num> 255) || (num< 0)){
>
> return;
> }
>
> try{
> bits[num] = col;<--
>
> }
> catch (char * str){
> MessageBox(NULL, str, "Info", MB_OK);
> }

There isn't enough context to provide an answer. Array access certainly
doesn't throw!

--
Ian Collins
From: JoeC on
On Mar 31, 9:37 pm, Ian Collins <ian-n...(a)hotmail.com> wrote:
> On 04/ 1/10 01:39 PM, JoeC wrote:
>
>
>
> > I have read some on exception handling but I never really understood
> > it or how to use it.  Now I am running into problems using an array.
> > I have tracked my bugs to this line.  I want to see what the problem
> > is.
>
> >   Is this correct?
>
> >    if((num>  255) || (num<  0)){
>
> >            return;
> >    }
>
> >    try{
> >      bits[num] = col;<--
>
> >    }
> >    catch (char * str){
> >             MessageBox(NULL, str, "Info", MB_OK);
> >    }
>
> There isn't enough context to provide an answer.  Array access certainly
> doesn't throw!
>
> --
> Ian Collins

I am working on the program and trying to track down where the
problems are. I wish I know someone who could look at my program and
point out where I could be going wrong. It is too difficult to post
all the code and no one would go through it. I wish I knew where to
look to find where I am getting access violations.

From: Ian Collins on
On 04/ 1/10 05:19 PM, JoeC wrote:
>
> I am working on the program and trying to track down where the
> problems are. I wish I know someone who could look at my program and
> point out where I could be going wrong. It is too difficult to post
> all the code and no one would go through it. I wish I knew where to
> look to find where I am getting access violations.

Access violations != exceptions.

You want to use whatever memory access checking tools your platform
supports.

--
Ian Collins
From: Ike Naar on
In article <0c1c94e4-c5e9-4e76-aa83-b37e07c94857(a)q16g2000yqq.googlegroups.com>,
JoeC <enki034(a)yahoo.com> wrote:
>I am working on the program and trying to track down where the
>problems are. I wish I know someone who could look at my program and
>point out where I could be going wrong. It is too difficult to post
>all the code and no one would go through it.

Then reduce the amount of code by taking away the parts that are not
relevant to your problem. During that process, you might find the cause
of the problem yourself; anyway, you'll end up with a smaller piece of
code that still has the problem, and that you *can* post.

It's nice if people can take the posted code "as-is", compile it, and
run it. So make sure the code that you post is complete and compiles
without errors. Also post the input to the program, and the expected
output.

>I wish I knew where to
>look to find where I am getting access violations.

Hints:
- inspect the code *very* carefully and understand what it does
- try to explain the code to somebody else
- turn up the warning level of your compiler and pay close attention
to the warnings that you get
- add print statements to the code that show the value of relevant
variables at key points
- run the code in a debugger
- use a memory-checking tool, such as valgrind
- 'play' with the input; start with the most trivial test case and
see if the program produces a correct result; then increase the
complexity of the test input, little by little, everytime seeing to
it that the program keeps producing the expected results.