SlideShare a Scribd company logo
1 of 15
Download to read offline
Reading Effective 
Java 第3回あなたとJava 
2014.08.08 (Fri) 
@kawakubox
項目57 
例外的状況にだけ例外を使用する
XV]_ 
MRXM! 
[LMPI
XVYI
_ 
QSYRXEMRW?MAGPMQF
a 
!? 
aGEXGL
%VVE]-RHI3YX3JSYRHW)GITXMSRI
_ 
! 
a
あ…ありのまま 今 起こった事を話すぜ! 
! 
おれは配列の要素を走査する処理を書いてくれと頼んだと思ったら、 
try-catchで括られたコードがcomittされてたんだ。 
! 
な…何を言っているのか わからねーと思うが 
おれも 何をされたのか わからなかった…
API設計者へ告ぐ… 
API利用者に通常のフローで例外を強制しないこと。 
! 
Iteratorパターン利用したAPIを例に挙げる 
JSV
-XIVEXSV 'EVHMXI!GEVHWMXIVEXSV
MXILEW2IX
_ 
'EVHGEVH!MXIRIX
a 
next()メソッドは、iteratorの位置に依存している 
➡状態依存メソッド 
hasNext()メソッドは、次の要素の有無を検査する 
➡状態検査メソッド 
! 
状態検査メソッドがないAPIを立付けると、 
例外を捕捉することでしか配列走査処理を実装できなくなる。
項目58 
回復可能な状態にはチェックされる例外を、 
プログラミングエラーには実行時例外を使用する
 Javaにおける例外/エラーの種類 
Exception 
Throwable 
Error 
Runtime 
Exception 
OreOreThrowable 
MyError 
OutOfMemory 
GirlfriendNotExists 
Owata Exception 
Exception 
Error 
API呼び出し側で回復できるような 
状況にはチェックされる例外を適 
用する
 Javaにおける例外/エラーの種類 
Exception 
Throwable 
Error 
Runtime 
Exception 
OreOreThrowable 
MyError 
プログラミングエラーには実行時 
OutOfMemory 
例外を適用する 
GirlfriendNotExists 
Owata Exception 
Exception 
Error 
ex) APIの事前条件エラーなど

More Related Content

Viewers also liked

Master AIRE 2014
Master AIRE 2014Master AIRE 2014
Master AIRE 2014CRI Paris
 
Thompson.Orlandi.Williams.DRAFT presentation
Thompson.Orlandi.Williams.DRAFT presentationThompson.Orlandi.Williams.DRAFT presentation
Thompson.Orlandi.Williams.DRAFT presentationcassye2820
 
01 04 wh_james_dininno
01 04 wh_james_dininno01 04 wh_james_dininno
01 04 wh_james_dininnoJames Dininno
 
Participative tools emerging at the CRI
Participative tools emerging at the CRIParticipative tools emerging at the CRI
Participative tools emerging at the CRICRI Paris
 
Night Science 2012 booklet
Night Science 2012 bookletNight Science 2012 booklet
Night Science 2012 bookletCRI Paris
 
Dsk dunia seni visual thn 3
Dsk dunia seni visual thn 3Dsk dunia seni visual thn 3
Dsk dunia seni visual thn 3Nordin Laguda
 
India Union Budget - 2016
India Union Budget - 2016India Union Budget - 2016
India Union Budget - 2016Sangesh Sase
 

Viewers also liked (8)

Master AIRE 2014
Master AIRE 2014Master AIRE 2014
Master AIRE 2014
 
Biblnk
BiblnkBiblnk
Biblnk
 
Thompson.Orlandi.Williams.DRAFT presentation
Thompson.Orlandi.Williams.DRAFT presentationThompson.Orlandi.Williams.DRAFT presentation
Thompson.Orlandi.Williams.DRAFT presentation
 
01 04 wh_james_dininno
01 04 wh_james_dininno01 04 wh_james_dininno
01 04 wh_james_dininno
 
Participative tools emerging at the CRI
Participative tools emerging at the CRIParticipative tools emerging at the CRI
Participative tools emerging at the CRI
 
Night Science 2012 booklet
Night Science 2012 bookletNight Science 2012 booklet
Night Science 2012 booklet
 
Dsk dunia seni visual thn 3
Dsk dunia seni visual thn 3Dsk dunia seni visual thn 3
Dsk dunia seni visual thn 3
 
India Union Budget - 2016
India Union Budget - 2016India Union Budget - 2016
India Union Budget - 2016
 

Recently uploaded

論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案sugiuralab
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 

Recently uploaded (8)

論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 

Reading effective java_3rd