title: Why does AudioServicesCreateSystemSoundID throw an exception internally but return 0 as an error code?
body: <p>I’m running an iOS program in the 4.3.2, 5.0, and 5.1 Simulators, and I’m hitting a weird internal exception in AudioToolbox. I have a breakpoint set in Xcode (Xcode 4.3.1, running on 10.7.3) for all exceptions, and the debugger is breaking during a call to <code>AudioServicesCreateSystemSoundID()</code>:</p>
  
  <pre><code>SystemSoundID soundID;
  OSStatus errorCode = AudioServicesCreateSystemSoundID(soundFileURLRef, &amp;soundID);
                    // ^ boom. ^
  </code></pre>
  
  <p>The backtrace:</p>
  
  <pre><code>(lldb) bt
  * thread #1: tid = 0x1f03, 0x9000e230 libc++abi.dylib`__cxa_throw, stop reason = breakpoint 1.2
  frame #0: 0x9000e230 libc++abi.dylib`__cxa_throw
  frame #1: 0x00144193 AudioToolbox`ID3ParserHandle::ID3ParserHandle(void*, long (*)(void*, unsigned long, unsigned long, unsigned long, void**, unsigned long*)) + 259
  frame #2: 0x001442de AudioToolbox`ID3ParserOpen + 62
  frame #3: 0x0006c0e7 AudioToolbox`MPEGAudioFile::ParseID3Tags() + 87
  frame #4: 0x0006c2ba AudioToolbox`MPEGAudioFile::ParseAudioFile() + 26
  frame #5: 0x00015153 AudioToolbox`AudioFileOpenWithCallbacks + 371
  frame #6: 0x00027020 AudioToolbox`_ZL15VerifyAndMapURLPK7__CFURLRx + 448
  frame #7: 0x00026d85 AudioToolbox`_ZL18ActionDataToServerPK7__CFURLm + 933
  frame #8: 0x000da26b AudioToolbox`AudioServicesCreateSystemSoundID + 235
  frame #9: 0x00005be1 app`-[SoundsViewController playSoundForPath:] + 257 at SoundsViewController.m:161
  frame #10: 0x00005a99 app`-[SoundsViewController tableView:didSelectRowAtIndexPath:] + 777 at SoundsViewController.m:129
  frame #11: 0x0029db68 UIKit`-[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
  frame #12: 0x00293b05 UIKit`-[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
  frame #13: 0x009ad79e Foundation`__NSFireDelayedPerform + 441
  frame #14: 0x00fb58c3 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
  frame #15: 0x00fb6e74 CoreFoundation`__CFRunLoopDoTimer + 1220
  frame #16: 0x00f132c9 CoreFoundation`__CFRunLoopRun + 1817
  frame #17: 0x00f12840 CoreFoundation`CFRunLoopRunSpecific + 208
  frame #18: 0x00f12761 CoreFoundation`CFRunLoopRunInMode + 97
  frame #19: 0x01f6b1c4 GraphicsServices`GSEventRunModal + 217
  frame #20: 0x01f6b289 GraphicsServices`GSEventRun + 115
  frame #21: 0x00234c93 UIKit`UIApplicationMain + 1160
  frame #22: 0x00002c45 app`main + 181 at main.m:14
  </code></pre>
  
  <p>However, the audio file in <code>soundID</code> is created successfully, and the OSStatus error code that <code>AudioServicesCreateSystemSoundID</code> returns is 0.</p>
  
  <p>This happens in all three iOS Simulator versions I have installed, and on my iPhone running 5.1.</p>
  
  <p>This looks to be the same general backtrace as <a href="https://stackoverflow.com/questions/9683547/avaudioplayer-throws-breakpoint-in-debug-mode">AVAudioPlayer throws breakpoint in debug mode</a> , though mine is the result of a more direct invocation of AudioToolbox.</p>
  
  <p>I want to file this with Apple, since it’s a bug in AudioToolbox (frameworks shouldn’t use exceptions for flow control, per bbum and others), but before I do, I’m wondering what other info I can gather to give them, and if there’s any way to avoid this throw (maybe by tweaking ID3 tags in this mp3?)</p>