The exception must be handled when the user enters the number 0 as a denominator. But i do not know how to implement? Can anyone be so kind to give me a hint and the correct syntax?

Thanks

05-22-2006

whiteflags

To use exception handling properly, you need an exception class, and another class that the program uses. When runtime errors occur in your program's class, you need to throw() your exception. Then somewhere in your program the exception should be handled with a try/catch block.

And besides that, you included standard exceptions, but you're not using them. If I wrote your code, I would use it.

Just to be clear, if your functions' signature has a throw(type) statement in it, this tells the compiler that you want to limit the function's exceptions down to a certain type. In my example, I allowed Calculate to throw only DevideByZero exceptions because I was confident that it would be the only type of exception. If you write throw() in a function's signature, you are telling the compiler that the function will never throw any exceptions.

this is known as the basic guarentee and all your code should strive to emulate this behaviour.

you may not even care about memory ('who cares about memory? I've got 2 gigs and the os will clean up anyway'), but your users will be pretty annoyed if they find your app has locked their files or acquired all the graphics objects!

05-22-2006

whiteflags

Quote:

Originally Posted by ChaosEngine

In practice, a functions exception specification is often little more than documentation. Many compilers ignore it.

It is, in fact, standard behavior. Just because compilers are missing something from the standard doesn't mean you should ignore it and not use it, and what's the harm? If the compiler ignores it, nothing happens that's bad.

05-22-2006

ChaosEngine

Quote:

Originally Posted by citizen

It is, in fact, standard behavior. Just because compilers are missing something from the standard doesn't mean you should ignore it and not use it, and what's the harm? If the compiler ignores it, nothing happens that's bad.

because it's a waste of time and energy. Even java acknowledges that exception specifications are more effort than they're worth.