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

My record label anaylsis
My record label anaylsisMy record label anaylsis
My record label anaylsis
Danpalacefan
 
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
sophiejane27
 
لماذا تضحي الولايات المتحدة بمصالحها من أجل إسرائيل؟
لماذا تضحي الولايات المتحدة بمصالحها من أجل إسرائيل؟لماذا تضحي الولايات المتحدة بمصالحها من أجل إسرائيل؟
لماذا تضحي الولايات المتحدة بمصالحها من أجل إسرائيل؟
Ibrahimia Church Ftriends
 

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

Recently uploaded (10)

Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 

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