# Std::out\_of\_range exception in executeLaunch()

**URL:** <https://discourse.libcinder.org/t/std-out-of-range-exception-in-executelaunch/156>\
**Category:** Using Cinder\
**Created:** [July 15, 2016, 11:27pm UTC](https://discourse.libcinder.org/t/std-out-of-range-exception-in-executelaunch/156 "2016-07-15T23:27:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![navadria](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/navadria/32/90_2.png) [@navadria](https://discourse.libcinder.org/u/navadria)\
**Post date:** [July 15, 2016, 11:27pm UTC](https://discourse.libcinder.org/t/std-out-of-range-exception-in-executelaunch/156/1 "2016-07-15T23:27:03Z")

</div>

I’m developing an app that reads serial data that’s sent every frame by an Arduino, stores it, displays it and forwards some events via OSC.

Every few launches I get a crash that I haven’t been able to trace. It’s a `vector std::out_of_range` exception in [this line](https://github.com/cinder/Cinder/blob/master/src/cinder/app/AppBase.cpp#L137) of executeLaunch ([this one](https://github.com/cinder/Cinder/blob/master/src/cinder/app/cocoa/AppMac.cpp#L50) in the implementation file).

I have no idea what vector is causing the crash and I haven’t been able to replicate it in a separate app yet. Any tips on debugging these kinds of things?

---

<div class="post-metadata">

**Author:** ![rich.e](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/rich.e/32/1025_2.png) [@rich.e](https://discourse.libcinder.org/u/rich.e)\
**Post date:** [July 16, 2016, 8:12am UTC](https://discourse.libcinder.org/t/std-out-of-range-exception-in-executelaunch/156/2 "2016-07-16T08:12:25Z")

</div>

Try breaking on exceptions, with whatever IDE you’re using.

---

<div class="post-metadata">

**Author:** ![navadria](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/navadria/32/90_2.png) [@navadria](https://discourse.libcinder.org/u/navadria)\
**Post date:** [July 17, 2016, 9:32pm UTC](https://discourse.libcinder.org/t/std-out-of-range-exception-in-executelaunch/156/3 "2016-07-17T21:32:19Z")

</div>

Thanks Rich. I’m doing that already, but I can’t really step in or out of `executeLaunch()`. The debugger drops me there even though I have my setup, update and draw surrounded by try/catch.

---

<div class="post-metadata">

**Author:** ![rich.e](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/rich.e/32/1025_2.png) [@rich.e](https://discourse.libcinder.org/u/rich.e)\
**Post date:** [July 18, 2016, 6:13am UTC](https://discourse.libcinder.org/t/std-out-of-range-exception-in-executelaunch/156/4 "2016-07-18T06:13:37Z")

</div>

That `catch` in `excecuteLaunch()` will only be hit if the exception goes uncaught. Perhaps the exception is happening on a background thread?

In any event, make sure you are breaking on the _throw_, if that is working then it should break you right where the `std::vector::at()` was called with an out of bounds argument.

---

<div class="post-metadata">

**Author:** ![sansumbrella](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/sansumbrella/32/30_2.png) [@sansumbrella](https://discourse.libcinder.org/u/sansumbrella)\
**Post date:** [July 18, 2016, 3:50pm UTC](https://discourse.libcinder.org/t/std-out-of-range-exception-in-executelaunch/156/5 "2016-07-18T15:50:51Z")

</div>

To break on exceptions, you will want to add a “symbolic breakpoint.” Depending on your platform, how you do this will vary (and the name might, too).

Apple has a [tiny guide](https://developer.apple.com/library/ios/recipes/xcode_help-breakpoint_navigator/articles/adding_a_symbolic_breakpoint.html) for setting these up in XCode.

---

<div class="post-metadata">

**Author:** ![navadria](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/navadria/32/90_2.png) [@navadria](https://discourse.libcinder.org/u/navadria)\
**Post date:** [July 18, 2016, 6:11pm UTC](https://discourse.libcinder.org/t/std-out-of-range-exception-in-executelaunch/156/6 "2016-07-18T18:11:35Z")

</div>

Awesome, that worked. Never used that kind of breakpoints before, thanks. 👍

EDIT: actually, my main error was writing ci::Exception in my catch statements, which wasn’t working in this case because this was an std::exception. Just in case it helps someone else in the future.

---

<div class="post-metadata">

**Author:** ![sansumbrella](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/sansumbrella/32/30_2.png) [@sansumbrella](https://discourse.libcinder.org/u/sansumbrella)\
**Post date:** [July 20, 2016, 6:11pm UTC](https://discourse.libcinder.org/t/std-out-of-range-exception-in-executelaunch/156/7 "2016-07-20T18:11:35Z")

</div>

[ci::Exception inherits from std::exception](https://github.com/cinder/Cinder/blob/master/include/cinder/Exception.h#L31), so a properly-written catch block can catch either. Just make sure you are catching by const reference so polymorphism is possible.

```auto
try {
    …
}
catch (const ci::Exception &exc) {
    CI_LOG_E("Caught some exception: " << exc.what());
}

```

---

<div class="post-metadata">

**Author:** ![sansumbrella](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/sansumbrella/32/30_2.png) [@sansumbrella](https://discourse.libcinder.org/u/sansumbrella)\
**Post date:** [July 20, 2016, 6:12pm UTC](https://discourse.libcinder.org/t/std-out-of-range-exception-in-executelaunch/156/8 "2016-07-20T18:12:16Z")

</div>

Never mind the catch block I wrote previously. The type polymorphism only accepts downstream variants, so catching std::exception will work for ci::Exception, but not the other way around.
