How do I use try…catch to catch floating point errors?

后端 未结 4 820
野的像风
野的像风 2020-12-11 02:22

I\'m using c++ in visual studio express to generate random expression trees for use in a genetic algorithm type of program.

Because they are random, the trees often

4条回答
  •  悲哀的现实
    2020-12-11 03:02

    Never tried it, but assuming divide by zero throws an exception, you could just wrap the code in a try/catch like this:

    try { // potential divide by zero... } catch(...) { // ... catches ALL exceptions }

提交回复
热议问题