[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

when to throw an exception?? I know what exceptions are, but

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 10
Thread images: 1

File: 4548490.jpg (4KB, 100x100px) Image search: [Google]
4548490.jpg
4KB, 100x100px
when to throw an exception??

I know what exceptions are, but when are they needed over code logic?
>>
>>60858037

when you reach a point where the program literally cannot perform as required due to bad user input
>>
When there is something outside the scope/control of your program that is capable of erroring out and taking your program down with it. I view TCP as an example. You pretty much need exception handling around TCP due to the number of ways it can fuck up that have nothing to do with you.
>>
>>60858086
This is the only acceptable answer
>>
You use exceptions instead of returning booleans when its deemed unlikely for something to go wrong but there is still a possibility of said thing going wrong.

Ex: Ajax requests, accessing shit without permission in android, accessing a memory address without permission inside a vector class in c++. Stuff like that.
>>
At random.

>Select random number from 00001-99999
>if this matches the last five digits of the Unix timecode, throw a cryptic exception
>Select another random number because 00000 and 99999
>This is the number of seconds before you repeat this
>>
>>60858183
What about catchable exceptions? If you catch it, you can recover from it, so why throw one in the first place?
>>
Never throw exceptions
>>
If it's catchable, it's fixable.
>>
>>60858728
>>60858664
If you are making a library, is better to throw the exceptions up to the main program can catch it and deal with them.

Ex: on MVC if your database is down and your model class failed to connect instead of catching the exception, throw it to the controller class and deal with it on the business layer.
Thread posts: 10
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.