Is it okay if I like to use exceptions in my code?
exception handling, I mean.
It is almost essential to use exception handling in code
But C doesn't have it :-P
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.
but it will make my code so cluttered :-)
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.
Thanks for that. You even found out where I learned how to program horribly :-P
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. ;) )
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.
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
Join our real-time social learning platform and learn together with your friends!