SlideShare a Scribd company logo
1 of 38
Download to read offline
∼時には起こせよ
エクセプション
永野哲久 7gano

iPhone Core Audioプログラミングという絶賛
絶版中でAmazonで1万円超のプレミアムがつ
いている本を書きました"
COOKPADではCore Audioのコードは1行も書
いていません

現在、ROLLCAKE inc. に出向、取り締まり中

Core Audioのコードは1行も書いていません
id object;
...
NSMutableDictionary *dict;
dict = [NSMutableDictionary new];
dict[@"key"] = object;
あ∼ このコード、たまに


objectがnilの場合があるなぁ
Exception[33092:70b] *** Terminating app due
to uncaught exception
'NSInvalidArgumentException', reason: '***
setObjectForKey: object cannot be nil (key:
key)'
*** First throw call stack:
すぐ落ちます!★1つです!
すぐ落ちます!★1つです!
すぐ落ちます!★1つです!
すぐ落ちます!★1つです!
すぐ落ちます!★1つです!
すぐ落ちます!★1つです!
すぐ落ちます!★1つです!
すぐ落ちます!★1つです!
すぐ落ちます!★1つです!
すぐ落ちます!★1つです!
クイズで覚えるエクセプション
@try {
NSMutableArray* mutableArray;
mutableArray = [NSMutableArray new];
[mutableArray addObject:nil];
NSLog(@"◎");
}@catch (NSException *exception) {
NSLog(@"exception = %@", exception);
}
例外発生
*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
@try {
NSMutableArray* mutableArray;
mutableArray = [NSMutableArray new];
[mutableArray addObject:[NSObject new]];
id obj = [mutableArray objectAtIndex:1];
NSLog(@"◎");
}@catch (NSException *exception) {
NSLog(@"exception! %@", exception);
}
例外発生
-[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]
@try {
NSMutableArray* mutableArray;
mutableArray = [NSMutableArray new];
NSUInteger index;
index = [mutableArray indexOfObject:nil];
NSLog(@"◎");
}@catch (NSException *exception) {
NSLog(@"exception! %@", exception);
}
○
@try {
NSMutableArray* mutableArray;
mutableArray = [NSMutableArray new];
[mutableArray removeObject:nil];
NSLog(@"◎");
}@catch (NSException *exception) {
NSLog(@"exception! %@", exception);
}
○
@try {
NSMutableDictionary* dictionary;
dictionary = [NSMutableDictionary new];
[dictionary setObject:nil forKey:@"key"];
NSLog(@"◎");
}@catch (NSException *exception) {
NSLog(@"exception! %@", exception);
}
例外発生
*** setObjectForKey: object cannot be nil (key: key)
@try {
NSMutableDictionary* dictionary;
dictionary = [NSMutableDictionary new];
[dictionary setObject:@"object" forKey:nil];
NSLog(@"◎");
}@catch (NSException *exception) {
NSLog(@"exception! %@", exception);
}
例外発生
*** setObjectForKey: key cannot be nil
@try {
NSMutableDictionary* dictionary;
dictionary = [NSMutableDictionary new];
id obj = [dictionary objectForKey:nil];
NSLog(@"◎");
}@catch (NSException *exception) {
NSLog(@"exception! %@", exception);
}
○
@try {
NSMutableDictionary* mutableDictionary;
mutableDictionary = [NSMutableDictionary new];
[mutableDictionary removeObjectForKey:nil];
NSLog(@"◎");
}@catch (NSException *exception) {
NSLog(@"exception! %@", exception);
}
例外発生
*** -[__NSDictionaryM removeObjectForKey:]: key cannot be nil
@try {
[@(1) isEqualToNumber:nil];
NSLog(@"◎");
}@catch (NSException *exception) {
NSLog(@"exception! %@", exception);
}
例外発生
-[__NSCFNumber compare:]: nil argument
え、compare: ?
@try {
[@"A" isEqualToString:nil];
NSLog(@"◎");
}@catch (NSException *exception) {
NSLog(@"exception! %@", exception);
}
○
え、なんでこっちは
OK系 ?
@try {
[NSString stringWithString:nil];
NSLog(@"◎");
}@catch (NSException *exception) {
NSLog(@"exception! %@", exception);
}
例外発生
*** -[NSPlaceholderString initWithString:]: nil argument
@try {
UIView *view = [UIView new];
[view addSubview:nil];
NSLog(@"◎");
}@catch (NSException *exception) {
NSLog(@"exception! %@", exception);
}
○
これは例外の方がよく
ないか?
凶悪なやつ
CFRetain(nil);
"

CFRelease(nil);
SIGKILL
nilでエクセプションが発生す
る場合を覚えて、世の中から
クラッシュを無くそう

More Related Content

Viewers also liked

M.Phil Computer Science Wireless Communication Projects
M.Phil Computer Science Wireless Communication ProjectsM.Phil Computer Science Wireless Communication Projects
M.Phil Computer Science Wireless Communication ProjectsVijay Karan
 
RE/MAX Estate Properties Listing Syndication
RE/MAX Estate Properties Listing SyndicationRE/MAX Estate Properties Listing Syndication
RE/MAX Estate Properties Listing SyndicationJames Sanders
 
My record label anaylsis
My record label anaylsisMy record label anaylsis
My record label anaylsisDanpalacefan
 
Sophie lee a2 advanced portfolio_production_diary_template
Sophie lee a2 advanced portfolio_production_diary_templateSophie lee a2 advanced portfolio_production_diary_template
Sophie lee a2 advanced portfolio_production_diary_templatesophiejane27
 
Irregularities in Traffic Forecasts
Irregularities in Traffic ForecastsIrregularities in Traffic Forecasts
Irregularities in Traffic ForecastsBasil Psarianos
 
لماذا تضحي الولايات المتحدة بمصالحها من أجل إسرائيل؟
لماذا تضحي الولايات المتحدة بمصالحها من أجل إسرائيل؟لماذا تضحي الولايات المتحدة بمصالحها من أجل إسرائيل؟
لماذا تضحي الولايات المتحدة بمصالحها من أجل إسرائيل؟Ibrahimia Church Ftriends
 
Web 2. son
Web 2. sonWeb 2. son
Web 2. sonhikolan
 
Eines 2.0 per a tasques de tècnics sessió 4
Eines 2.0 per a tasques de tècnics sessió 4Eines 2.0 per a tasques de tècnics sessió 4
Eines 2.0 per a tasques de tècnics sessió 4Neus Burch Suñer
 

Viewers also liked (16)

Kondisi kependudukan
Kondisi kependudukanKondisi kependudukan
Kondisi kependudukan
 
Legacy of alexander
Legacy of alexanderLegacy of alexander
Legacy of alexander
 
El huerto 3º
El huerto 3ºEl huerto 3º
El huerto 3º
 
M.Phil Computer Science Wireless Communication Projects
M.Phil Computer Science Wireless Communication ProjectsM.Phil Computer Science Wireless Communication Projects
M.Phil Computer Science Wireless Communication Projects
 
RE/MAX Estate Properties Listing Syndication
RE/MAX Estate Properties Listing SyndicationRE/MAX Estate Properties Listing Syndication
RE/MAX Estate Properties Listing Syndication
 
Jm liquids
Jm liquidsJm liquids
Jm liquids
 
Giaoanbai30
Giaoanbai30Giaoanbai30
Giaoanbai30
 
Mercabarna
MercabarnaMercabarna
Mercabarna
 
My record label anaylsis
My record label anaylsisMy record label anaylsis
My record label anaylsis
 
Sophie lee a2 advanced portfolio_production_diary_template
Sophie lee a2 advanced portfolio_production_diary_templateSophie lee a2 advanced portfolio_production_diary_template
Sophie lee a2 advanced portfolio_production_diary_template
 
טיולי ג'יפים 0502232798
טיולי ג'יפים     0502232798טיולי ג'יפים     0502232798
טיולי ג'יפים 0502232798
 
Irregularities in Traffic Forecasts
Irregularities in Traffic ForecastsIrregularities in Traffic Forecasts
Irregularities in Traffic Forecasts
 
لماذا تضحي الولايات المتحدة بمصالحها من أجل إسرائيل؟
لماذا تضحي الولايات المتحدة بمصالحها من أجل إسرائيل؟لماذا تضحي الولايات المتحدة بمصالحها من أجل إسرائيل؟
لماذا تضحي الولايات المتحدة بمصالحها من أجل إسرائيل؟
 
Web 2. son
Web 2. sonWeb 2. son
Web 2. son
 
Ijic final-cover
Ijic final-coverIjic final-cover
Ijic final-cover
 
Eines 2.0 per a tasques de tècnics sessió 4
Eines 2.0 per a tasques de tècnics sessió 4Eines 2.0 per a tasques de tècnics sessió 4
Eines 2.0 per a tasques de tècnics sessió 4
 

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
 
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
 
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
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Danieldanielhu54
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
論文紹介: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
 
論文紹介: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
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 

Recently uploaded (10)

論文紹介: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
 
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
 
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」の紹介
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Daniel
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
論文紹介: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
 
論文紹介: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...
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 

ときには起こせよエクセプション