Howto break at "{double d=0; d=d/d;}" in VC? 
Author Message
 Howto break at "{double d=0; d=d/d;}" in VC?

Could anybody just post an example code that makes something happen at
the (*) line with zero division ? (like de{*filter*} breakpoint or handler
funtion execution) ? I must be a real idiot but I don't understand why
... I am using VC default compiling options, do I need to do anything
with them?

main() {
double d;
    // . . .
    d = 0;
    d = d/d;  // (*)
    // . . .

Quote:
}

I have tried several methods, including 'signal' function,
__try / __except
setting debug/exceptions all item to "stop always",
playing with all exception-related options ...

What I have never seen is anything happening at command line where zero
division is used.
However , I have seen lot of documentation and even examples that talk
about zero division exception etc.
What is the problem?

JT



Sat, 27 Sep 2003 21:53:49 GMT  
 Howto break at "{double d=0; d=d/d;}" in VC?
If you want to break into the de{*filter*} then use the Exceptions dialog that
is available when you're debugging.  Set the Divide By Zero exception to
Stop Always.

If you want to handle it in code then use the following (taken from MSDN)

#include <fpieee.h>
#include <excpt.h>
#include <float.h>

//Floating-point exception handler
int fpieee_handler( _FPIEEE_RECORD *pieee )
{
   // user-defined ieee trap handler routine:
   // there is one handler for all
   // IEEE exceptions

   // Assume the user wants all invalid
   // operations to return 0.

   if ((pieee->Cause.InvalidOperation) &&
       (pieee->Result.Format == _FpFormatFp32))
   {
        pieee->Result.Value.Fp32Value = 0.0F;

        return EXCEPTION_CONTINUE_EXECUTION;
   }
   else
      return EXCEPTION_EXECUTE_HANDLER;

Quote:
}

#define _EXC_MASK    \
    _EM_UNDERFLOW  + \
    _EM_OVERFLOW   + \
    _EM_ZERODIVIDE + \
    _EM_INEXACT

void main( void )
{
   // ...

   __try {
      // unmask invalid operation exception
      _controlfp(_EXC_MASK, _MCW_EM);

      // code that may generate
      // fp exceptions goes here
   }
   __except ( _fpieee_flt( GetExceptionCode(),
                GetExceptionInformation(),
                fpieee_handler ) ){

      // code that gets control

      // if fpieee_handler returns
      // EXCEPTION_EXECUTE_HANDLER goes here

   }

   // ...

Quote:
}

Refer to CUJ June 2000 and subsequent issues on how to handle floating point
values correctly in the Journeyman's Shop column by Pete Becker.

--
Michael Taylor,MCP
DCS Corp.


Quote:

> Could anybody just post an example code that makes something happen at
> the (*) line with zero division ? (like de{*filter*} breakpoint or handler
> funtion execution) ? I must be a real idiot but I don't understand why
> ... I am using VC default compiling options, do I need to do anything
> with them?

> main() {
> double d;
>     // . . .
>     d = 0;
>     d = d/d;  // (*)
>     // . . .
> }

> I have tried several methods, including 'signal' function,
> __try / __except
> setting debug/exceptions all item to "stop always",
> playing with all exception-related options ...

> What I have never seen is anything happening at command line where zero
> division is used.
> However , I have seen lot of documentation and even examples that talk
> about zero division exception etc.
> What is the problem?

> JT



Sat, 27 Sep 2003 22:41:14 GMT  
 Howto break at "{double d=0; d=d/d;}" in VC?

Quote:

> If you want to break into the de{*filter*} then use the Exceptions dialog that
> is available when you're debugging.  Set the Divide By Zero exception to
> Stop Always.

> If you want to handle it in code then use the following (taken from MSDN)

The handler sample code works! Thank you very much!
But the de{*filter*} break does not work  on my Visual C++ 6.0 (No Service Packs)

Start Debug/Step Into
Debug/Exceptions/Float Divide by Zero/Set Stop Always
Debug/Go

does not break at zero division lines. Even if I set all possible exceptions in
list to Stop Always. That I have tried many times.

void main() {
 double d1,d2;
 float f1;

 d1 = 0;  d2 = 1;
 d1 = d2/d1;
 f1 = 0;  f1 = f1/f1;

Quote:
}

JT


Sun, 28 Sep 2003 14:22:24 GMT  
 Howto break at "{double d=0; d=d/d;}" in VC?

Quote:

>Could anybody just post an example code that makes something happen at
>the (*) line with zero division ? (like de{*filter*} breakpoint or handler
>funtion execution) ?

>main() {
>double d;
>    // . . .
>    d = 0;
>    d = d/d;  // (*)
>    // . . .
>}

Other people have replied, so this post is not really helping with
trapping "divide by zero" exceptions... but...

In maths, you have a variable, and call it X.  X is a real number.

X / X == 1 does it not ?

Jimbo



Sun, 28 Sep 2003 20:42:24 GMT  
 Howto break at "{double d=0; d=d/d;}" in VC?
You should get an exception. The only thing I can think of is that your code
is optimized away.
Turn off optimizations and make sure you're creating a debug version.

Salim.


Quote:

> Could anybody just post an example code that makes something happen at
> the (*) line with zero division ? (like de{*filter*} breakpoint or handler
> funtion execution) ? I must be a real idiot but I don't understand why
> ... I am using VC default compiling options, do I need to do anything
> with them?

> main() {
> double d;
>     // . . .
>     d = 0;
>     d = d/d;  // (*)
>     // . . .
> }

> I have tried several methods, including 'signal' function,
> __try / __except
> setting debug/exceptions all item to "stop always",
> playing with all exception-related options ...

> What I have never seen is anything happening at command line where zero
> division is used.
> However , I have seen lot of documentation and even examples that talk
> about zero division exception etc.
> What is the problem?

> JT



Mon, 29 Sep 2003 02:18:02 GMT  
 Howto break at "{double d=0; d=d/d;}" in VC?
0/0 is undefined.


Quote:

> >Could anybody just post an example code that makes something happen at
> >the (*) line with zero division ? (like de{*filter*} breakpoint or handler
> >funtion execution) ?

> >main() {
> >double d;
> >    // . . .
> >    d = 0;
> >    d = d/d;  // (*)
> >    // . . .
> >}

> Other people have replied, so this post is not really helping with
> trapping "divide by zero" exceptions... but...

> In maths, you have a variable, and call it X.  X is a real number.

> X / X == 1 does it not ?

> Jimbo
> --




Sat, 04 Oct 2003 04:02:45 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. pass "double *const *" ptr to fn expecting "const double *const *"

2. VC7: Injected "Invoke()" code appears broken

3. Error: "User break called from code.."

4. Why does this code break "IntelliSense"?

5. Broken Rule For "For -- Loop"

6. "Break"

7. Hidden MDI windows "break" Window Menu

8. the "break" keyword

9. HOWTO: throw "managed excpetions"

10. extern linkage to typedefed "identifier", howto?

11. "WHAT/WHERE/WHY/HOWTO": LEARN C/C++ TODAY list

12. easy question: Howto "mysubclass = mybaseclass"

 

 
Powered by phpBB® Forum Software