プログラミング初心者あるある

トレンド

1: 思考 2022/08/29(月) 14:21:14.308 ID:/ROWZKsr0NIKU
例外処理で途端にやる気なくなる…
exなんとか…

中間おすすめ記事: 思考ちゃんねる

.mm-ttl{ font-size:14px; margin-bottom: 15px;}
.mm-ttl .Ttl-mil{ font-size:14px !important; color: gray;}
.mm-ttl .Ttl-mil span{ color: rgb(0, 128, 0); font-size: 15px !important; font-weight: bold;}
.at_out ul{-webkit-padding-start: 0; margin: 0 !important; padding: 0;}
.at_out li{ list-style-type:none !important; font-size:16px; line-height:1.2; font-weight: bold; margin-left: 0 !important; margin-bottom: 20px !important;}
.at_out li a{ text-decoration:underline; color:rgb(0, 102, 204); list-style-type:none;}
.pc_none{ display:none;}
.sp_none{ display:block;}

34: 思考 2022/08/29(月) 14:48:51.741 ID:vHdgbikD0NIKU
提供されてるプログラム呼び出すなら普通にtry catch使うよ
api「てめー、そんなことすんじゃねーよExceptionスローするぞオラァ」
って言われるから後はお前の好きなようにするだけ
「さっせんw上のプログラムに返事返しますわw」でもいいし
「>>1の設計クソだな!事前にチェックしてどうにかしろや!俺もExceptionスローしてやるわ!スローするのもお前が書いたんだけどなw」でもいいしな

35: 思考 2022/08/29(月) 14:49:58.403 ID:/ROWZKsr0NIKU
>>34
何いってんだこいつ…

2: 思考 2022/08/29(月) 14:21:46.300 ID:/ROWZKsr0NIKU
try catch(ex exなんとか)

3: 思考 2022/08/29(月) 14:21:53.129 ID:/ROWZKsr0NIKU
逆か?

4: 思考 2022/08/29(月) 14:23:02.628 ID:hIeKM9ZP0NIKU
最初に例外処理を扱うのはファイル入出力か
そりゃ当然だろ
お前のプログラムとファイルの間にはどんな邪魔が入るか分からんからな

5: 思考 2022/08/29(月) 14:26:44.760 ID:UFU1EB2Q0NIKU
俺が使う分には問題ないからヨシ!

6: 思考 2022/08/29(月) 14:26:45.969 ID:KAR2jWEmaNIKU
初心者が例外処理なんかやるか?
逆に初心者はヘタに例外処理せん方がええで

7: 思考 2022/08/29(月) 14:27:01.660 ID:/ROWZKsr0NIKU
いやテキストボックスに数字入れたいのに文字入ってたりするときだけど?

8: 思考 2022/08/29(月) 14:27:57.761 ID:1K9dQfLR0NIKU
>>7
ifで判断すりゃいいじゃん
例外投げる必要がない

中間おすすめ記事: 思考ちゃんねる

.mm-ttl{ font-size:14px; margin-bottom: 15px;}
.mm-ttl .Ttl-mil{ font-size:14px !important; color: gray;}
.mm-ttl .Ttl-mil span{ color: rgb(0, 128, 0); font-size: 15px !important; font-weight: bold;}
.at_out ul{-webkit-padding-start: 0; margin: 0 !important; padding: 0;}
.at_out li{ list-style-type:none !important; font-size:16px; line-height:1.2; font-weight: bold; margin-left: 0 !important; margin-bottom: 20px !important;}
.at_out li a{ text-decoration:underline; color:rgb(0, 102, 204); list-style-type:none;}
.pc_none{ display:none;}
.sp_none{ display:block;}

10: 思考 2022/08/29(月) 14:28:54.148 ID:/ROWZKsr0NIKU
>>8
ifよりtry catchの方がいいんじゃないの?
こういうときってifなの?

15: 思考 2022/08/29(月) 14:30:46.828 ID:1K9dQfLR0NIKU
>>10
わからないならわかる方法で実装しろ
そもそもその程度ならエラー処理するまでもない

9: 思考 2022/08/29(月) 14:28:25.482 ID:hIeKM9ZP0NIKU
>>7
そんなの強制終了する必要が無いんだから例外処理なんて必要がないだろ
何か間違ってる

13: 思考 2022/08/29(月) 14:30:02.375 ID:1K9dQfLR0NIKU
>>9
文字列をpreaseIntしようとして例外吐かれてるんだろ

16: 思考 2022/08/29(月) 14:32:22.093 ID:/ROWZKsr0NIKU
>>13
これ
内部で受け取った文字列をintへ変換してる
このときってif使うのが正解なのか?

17: 思考 2022/08/29(月) 14:34:28.054 ID:1K9dQfLR0NIKU
>>16
まず入力規則に沿ってるかどうかifで判定しろ
それから変換

それでも取り除けないエラーをtry catchするんだよ

62: 思考 2022/08/29(月) 16:09:52.164 ID:LFc1rE8a0NIKU
>>13
tryparseシラねぇのなら
いつものc#じゃないのか…

11: 思考 2022/08/29(月) 14:28:59.527 ID:UFU1EB2Q0NIKU
こういう用語用法間違いも初心者あるあるだよな

12: 思考 2022/08/29(月) 14:29:48.343 ID:/ROWZKsr0NIKU
なんでtry catchはダメなの?

14: 思考 2022/08/29(月) 14:30:33.159 ID:hIeKM9ZP0NIKU
>>12
例外処理ってのはプログラムで対応できない問題に対して強制終了することだぞ
なにか勘違いしてんじゃん

18: 思考 2022/08/29(月) 14:35:10.588 ID:/ROWZKsr0NIKU
>>14
この場合はif使うのか?
lf (文字列が数字であればってこと?)
でもテキストボックスは数字だけどテキスト(文字として拾う可能性があるのでは?)

19: 思考 2022/08/29(月) 14:35:55.950 ID:/ROWZKsr0NIKU
じゃあどういうときがtry catchなの?

21: 思考 2022/08/29(月) 14:37:41.588 ID:1K9dQfLR0NIKU
>>19
想定しないエラー、続行不可能なエラーの時

20: 思考 2022/08/29(月) 14:36:57.369 ID:0968B5gj0NIKU
ただのnumericチェックtry なんかやらんわ
用意された関数か、正規表現でチェックするのはif
想定外のエラーをtryで拾う

25: 思考 2022/08/31(水) 22:15:17
.netならtryParseみたいなパースできるかわからんやむを扱う関数があった気がするな

1001: 思考ちゃんねる

.ninki{ clear:both; margin-bottom: 15px;}
.mm-ttl{ font-size:14px;}
.mm-ttl .Ttl-mil{ font-size:15px !important; color: gray;}
.mm-ttl .Ttl-mil span{ color: rgb(0 128 0); font-size: 15px !important; font-weight: bold;}
.at_out ul{-webkit-padding-start: 0; margin: 0 !important; padding: 0;}
.at_out li{ list-style-type:none !important; font-size:16px; line-height:1.2; font-weight: bold; margin-left: 0 !important; margin-bottom: 20px !important;}
.at_out li a{ text-decoration:underline; color:rgb(0 102 204); list-style-type:none;}
.pc_none{ display:none;}
.sp_none{ display:block;}

Source: mindhack
プログラミング初心者あるある