Ask your own question, for FREE!
Mathematics 8 Online
OpenStudy (anonymous):

Is it okay if I like to use exceptions in my code?

OpenStudy (anonymous):

exception handling, I mean.

OpenStudy (a_clan):

It is almost essential to use exception handling in code

OpenStudy (anonymous):

But C doesn't have it :-P

OpenStudy (a_clan):

I googled and found this. Maybe it is of some help. http://www.on-time.com/ddj0011.htm Otherwise you will have to handle exception yourself by using IF-THEN-ELSE statements.

OpenStudy (anonymous):

but it will make my code so cluttered :-)

OpenStudy (anonymous):

I think you did the MIT 6.00 class. They used exceptions poorly. Exceptions should be for *exceptional* situations. In PS12 they had us throw an exception if a virus *didn't* reproduce. That seems like a pretty routine occurrence to me. It should be handled with a return value. An exception should be for trying to dereference null, or trying to parse "abc" as an integer, or trying to send data over a connection that's closed. Exceptions are expensive to throw. Use them when necessary (in exceptions to the normal expected flow of a program). Don't abuse them. Don't ignore them, but don't catch them if you don't handle them.

OpenStudy (anonymous):

Thanks for that. You even found out where I learned how to program horribly :-P

OpenStudy (anonymous):

lol. Yes, they made some pretty specious design decisions in that class. I think some of them were to try to expose people to certain programming topics (like using an exception to say a virus doesn't reproduce), but I think some of them were because they were professors and not professional programmers. (Don't tell them I said that. ;) )

OpenStudy (anonymous):

I just use exceptions whenever I expect something to proceed normally, but every so often there might be an error due to something missing or some invalid thing or etc.

OpenStudy (anonymous):

Yes, they should be outside the normal expected flow of the program. isPrime(1) could return False isPrime("cat") could probably throw an exception isPrime(-1) could go either way, but the function's documentation should say what it will do

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!