Lack of Error Checking | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Lack of Error Checking

In looking at many codes posted, I've noticed I'm able to break most of them very easily. Why is their code so visually complex, yet they fail to include exception handling, and often are missing clear instructions on what input they expect. So, my question for these coders is: What are the best resources for learning more on exception handling and error detection/avoidance/correction? Should code that breaks easily due to lack of these be voted down, even if it functions well given valid input?

11th Mar 2017, 9:12 PM
Sean VanMeter
Sean VanMeter - avatar
12 Answers
+ 12
In my opinion a good way to find errors is to write the code as simple and clean as you can. Also if possible get other coders to look through it.
11th Mar 2017, 9:38 PM
PureLogicality
PureLogicality - avatar
+ 3
i think 'good' exception handling is well beyond the scope of this program, so it's hard to agree with downvoting them here without it, i do think that code should have its own discussion area here, like a reply section where people can easily suggest fixes, give input, its kinda difficult to post code, post a q&a and expect people to go back and forth to discuss it. only exception i think is challenge questions, those should be downvoted if broken enough to make the questions not have an absolute answer
11th Mar 2017, 11:24 PM
William La Flamme
William La Flamme - avatar
+ 3
I've noticed the same thing. I personally try to handle as many exceptions as I can think of in my code no matter what, because it's good practise and good form, but as @William La Flamme said, "Good exception handling is well beyond the scope of this program." I don't think code should be down voted just because someone failed to attempt to catch and handle exceptions. My advice for error detection/avoidance/correction is to take a step back from your code periodically, and go "What happens if... ?". Then start coding contingencies from there. At the end of the day, the only way to catch them all is to let others play around with it. Speaking of letting others try to break things, give this one a shot. ;) https://code.sololearn.com/cD6J4mr5mNdS/#py
12th Mar 2017, 3:12 AM
Martian1oh1
Martian1oh1 - avatar
+ 2
A few websites I find useful are: HTML Reference: https://developer.mozilla.org/en-US/docs/Web/HTML JavaScript Guidelines: http://jstherightway.org/ JavaScript Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript CSS Reference: https://developer.mozilla.org/en-US/docs/Web/CSS Another HTML/CSS3/JS Coding Platform: http://codepen.io/
11th Mar 2017, 9:17 PM
Sean VanMeter
Sean VanMeter - avatar
+ 2
Martian1oh1: Since I thoroughly enjoy breaking things, I gave yours a go. Very well written. I was able to bug it out, though. When given 0999, 0000, and -001 as first line input (all 1 as second), the program caught no error and generated calendars anyway. Your code comments mentions it basically accepts any integer for the year, as long as it is 4 digits long, and voila. (I am sneaky!) :P Hopefully this reply catches your eye; didn't know how else to get it to you.
12th Mar 2017, 12:52 PM
Sean VanMeter
Sean VanMeter - avatar
+ 2
@Sean VanMeter: Cheers. Should be corrected now. :)
12th Mar 2017, 2:25 PM
Martian1oh1
Martian1oh1 - avatar
+ 2
@Hussain Al-Umran: Yes, it is possible to reverse it. The following would give you same results. leapCode = 0 if yyyy % 400 == 0: leapCode = 1 elif yyyy % 4 == 0 and yyyy % 100 != 0: leapCode = 1 else: leapCode = 0
12th Mar 2017, 3:09 PM
Martian1oh1
Martian1oh1 - avatar
+ 2
thanks
12th Mar 2017, 4:23 PM
Hussain Al-Umran
Hussain Al-Umran - avatar
+ 1
in the code if calander is it possible to reverse the condition of the leap year to put 400 in the 1st the the 4 in els if ?
12th Mar 2017, 2:48 PM
Hussain Al-Umran
Hussain Al-Umran - avatar
+ 1
@Martian1oh1: I CANNOT BREAKZ IT!!! :( Excellent correction and additions. That's exactly how code evolves! Functional -> Useful -> Necessary Seriously, though. Great code.
12th Mar 2017, 5:19 PM
Sean VanMeter
Sean VanMeter - avatar
0
@Sean, how do you know that wasn't his intent :p 0999 =999 AD, - 001= 1BC, and 0000 is 1AD on some calendar formats lol
12th Mar 2017, 4:03 PM
William La Flamme
William La Flamme - avatar
0
ma7in@gov.com
13th Mar 2017, 1:39 AM
seied morteza
seied morteza - avatar