東方中央幻視台

瞼の裏に弾幕が飛び交う程度の能力 - 永夜抄Normalはそれなりに難しい。

目次

Blog 利用状況

ニュース

自己紹介

関連サイト

投稿カレンダー

  • スクリプトをダウンロード!

ブログパーツ

Adsense

書庫

日記カテゴリ

逆効果な例外処理

C#を使い始めたばかりの初心者は、しばらくすると例外処理を覚えます。
このころだと十中八九catch句の中には例外が発生したことを通知するためのメッセージボックスを表示するコードを書きます。
しかし、それなりに複雑なコードを書くようになると、このメッセージボックスが煩わしくなります。
そうなると、catch句の中に何も書かなくなります。

しかし、空のcatch句を書くくらいならそもそも例外処理をしない方がずっと有益です。
なぜならこういったコードは間違いなく厄介なバグの温床になります。
というわけで、ユーザーに通知する必要のある例外(大抵はArgmentExceptionかIOException)はメッセージボックス、そうでない例外(ヌルポやIndexOutOfRangeException)は標準出力に吐くようにしておけばいいかと。

まあ実際面倒くさいのですが。

投稿日時 : 2007年1月6日 18:33

コメントを追加

# re: 逆効果な例外処理 2007/01/06 19:21 ue

初心者は try と finally だけで良いところにわざわざ中身の無い catch を書きます。
はい、昔の私です(^^;

# .NET はヌルポじゃなくてヌルリですね。

# re: 逆効果な例外処理 2007/01/06 19:25 囚人

ん~、.NET 例外は基本的に catch を書かないのが正攻法です。

ログ採りや、ユーザーへのやんわりメッセージ出力は、Windows アプリケーションなら Application.ThreadException で、コンソールアプリケーションなら AppDomain.UnhandledException で、Web アプリケーションなら HttpApplication.Error で、Web サービスなら Soap 拡張で、という具合です。

catch を使うのは例外の種類を差し替えたい場合や、そもそもある種の例外を握りつぶしてしまいたい場合等でしょう。

# re: 逆効果な例外処理 2007/01/06 19:54 Hirotow

> .NET はヌルポじゃなくてヌルリですね。
確かに普通にマネージコードを書いている限りはヌルリの方ですね。
あれはイベントハンドラを呼び出すときにnullチェックを忘れたりすると出てきます。

# re: 逆効果な例外処理 2007/01/15 14:12 null

> 確かに普通にマネージコードを書いている限りはヌルリの方ですね。
> あれはイベントハンドラを呼び出すときにnullチェックを忘れたりすると出てきます。

何か勘違いされているような・・・。
JavaはNullPointerException、.NETはNullReferenceExceptionという命名がされているので、Javaはヌルポ、.NETはヌルリですね。

あと、ArgmentException & IOException、RullReferenceException & IndexOutOfRangeException という分類ですが、ArgumentExceptionも後者 ( コーディングミスによって発生する例外 ) に属すると思います。

# casquette la 2013/03/04 14:06 http://www.b66.fr/

Really like often is the lively dread to your lifetime and then the expansion of whatever all of us passion. casquette la http://www.b66.fr/

# Nike Air Jordan Retro 3 2013/03/04 14:08 http://www.jordanretro3air.com/

Around the world could very well be a single person, then again to at least one guy / girl could very well be society. Nike Air Jordan Retro 3 http://www.jordanretro3air.com/

# Niketalk 2013/03/04 14:08 http://www.jordanretro10air.com/

To the world there's a chance you're an individual, however to personal there's a chance you're the entire world. Niketalk http://www.jordanretro10air.com/

# casquette swagg 2013/03/04 14:10 http://www.b66.fr/

A genuine family member is certainly one so , who overlooks your breakdowns and consequently can handle your achievements. casquette swagg http://www.b66.fr/

# Jordan 11 2013/03/04 14:10 http://www.nike44.com/

Should you want excellent data processing of one's cost, remember family. Jordan 11 http://www.nike44.com/

# pari street 2013/03/15 2:24 http://www.a88.fr/

Prefer is without a doubt frail through inception, however it spreads healthier with age whether it's competently feasted. pari street http://www.a88.fr/

# casquette monster 2013/03/16 3:43 http://www.b44.fr/

Preceptor‘g make an effort overtime, the best items are provided whilst you at a minimum hope the crooks to. casquette monster http://www.b44.fr/

# Shoes.fr 2013/03/17 2:29 http://www.c88.fr/

In no way lower, no matter if you can be unhappy, sinse you do not no who will diminishing excited about all your smile. Shoes.fr http://www.c88.fr/

# e66.fr 2013/03/23 14:34 http://e66.fr/

Do not glower, regardless if may miserable, when you can't say for sure the person becoming motivated by your primary satisfaction. e66.fr http://e66.fr/

# casquette superman 2013/03/23 14:34 http://e77.fr/

Like may lone rational and so solid answer to the problem having to do with mankinds presence. casquette superman http://e77.fr/

# usine23 2013/03/23 19:20 http://e55.fr/

Precisely where may perhaps be bond without any adore, we will have adore without any bond. usine23 http://e55.fr/

# destockchine 2013/03/26 0:52 http://c99.fr/

Real love may be the sole satisfied not to mention acceptable answer to the problem concerning individuals reputation. destockchine http://c99.fr/

# destock sport et mode 2013/04/03 2:19 http://www.ruenike.com/casquette-c-7.html/

The exact most awful path to fail to see anyone is intended to be meeting best suited anyway , they these animals knowing that you possibly can憑t|capital t|big t|to|testosterone levels|testosterone|w not|longer|l|r|g|s|h|d|p|T|metric ton|MT|tonne} get them. destock sport et mode http://www.ruenike.com/casquette-c-7.html/

# destockmania 2013/04/03 22:11 http://www.ruenike.com/vetement-homme-c-13.html/

Just because a professional doesn‘testosterone levels accept you and the choice of long for them to,doesn‘testosterone levels necessarily suggest these people don‘testosterone levels accept you boost they may have already. destockmania http://www.ruenike.com/vetement-homme-c-13.html/

# casquette obey 2013/04/04 18:32 http://www.ruenike.com/

For prosperity all family grasp united states of america; when trouble problems in later life all family. casquette obey http://www.ruenike.com/

# ruetn.fr 2013/04/08 3:51 http://www.ruetn.fr/

Really like is going to be fragile by inception, having said that it spreads more potent as we grow older whether it's competently given. ruetn.fr http://www.ruetn.fr/

タイトル
名前
URL
コメント