Skip to main content
12 events
when toggle format what by license comment
Jul 2, 2018 at 15:33 comment added user1451111 a slight optimization improvement in this answer's 3rd code snippet. By moving the if(n < 0) check in the very start of the function, two integer declarations can be saved.
Mar 30, 2016 at 20:02 comment added Giorgio @whatsisname: Why not? I mean, whose responsibility it is to handle an error depends on how you design your application.. You might do it in the example function or in the main function, or somewhere else.
Mar 29, 2016 at 23:26 comment added whatsisname @Luaan: that's not the responsibility of the example function, though.
Mar 29, 2016 at 8:52 comment added Luaan "Fail fast to the nearest safe state" is more reasonable. If you make your application so that it crashes when something unexpected happens, you risk losing the user's data. Places where the user's data is in jeopardy are great points for "penultimate" exception handling (there's always cases where you can do nothing but throw your hands up - the ultimate crash). Only making it crash in debug is just opening another can of worms - you need to test what you're deploying to the user anyway, and now you're spending half of your testing time on a version the user is never going to see.
Mar 28, 2016 at 20:07 comment added chux Hmmm, Could make the function valid over a wider domain Fibonacci numbers: Extension to negative integers
Mar 28, 2016 at 15:31 history edited user22815 CC BY-SA 3.0
added 57 characters in body
Mar 28, 2016 at 13:59 comment added JDługosz The question was using c#. Here's C++ (link to summary) for completeness.
Mar 28, 2016 at 11:18 history edited Kevin CC BY-SA 3.0
Taking JDługosz's advice to use an ArgumentException
Mar 28, 2016 at 10:30 comment added Kevin @JDługosz Yep! C# has an ArgumentException, and Java has an IllegalArgumentException.
Mar 28, 2016 at 8:06 comment added JDługosz Doesn't c# have a particular kind of exception to indicate invalid arguments or out-of-range arguments?
Mar 27, 2016 at 22:26 history edited Kevin CC BY-SA 3.0
added 9 characters in body
Mar 27, 2016 at 22:03 history answered Kevin CC BY-SA 3.0