c++ - How can I reduce the debugging overhead from non-exceptional exceptions -


we using api heavily relies on exceptions returning non-exceptional results. example of (out of many) ascertain whether user in group of people, have attempt group , interpret resultant "no group" exception. furthermore, these exceptions of 1 type.

we working on large , complex project using c++11 heavily multi-threaded, furthermore area working on concerns network communication, @ points have debug multiple instances concurrently.

our problem, , basis of question, arises because of impact non-exceptional exceptions have on our workflow. reticent turn off first-chance exception reporting single exception type thrown api because mean if have call api coder has missed try/catch block unwind main , loose context of call. if leave exceptions on simple non-exceptional behaviour, such described in example above, can result in multiple breaks (the initial throw , potentially rethrows), , can verify in fact non-exceptional exception querying stack, of non-main thread, find api call precipitated exception.

i believe our use case not unique others not have experienced same workflow issues, , question how should alter our debugging process in order better cope issues posed non-exceptional exceptions, described above.

we restricted using visual studio (or potentially windbg) debugging.

throwing exceptions in non-exceptional use case plain wrong imo. next step: every function void, gets returned throwing exceptions.

as far understand using thirdparty api shows odd behavior. here's consider when dealing "odd api" of kind, including c-apis pollute silly macros (yes, @ you, winapi):

  1. try avoid parts behave odd. in case: if there nonthrowing checks can call, it, i.e. call if(hasgroup) getgroup; else ... instead of try {getgroup;} catch(x) {...}
  2. instead of letting oddness ripple through code, constrain writing wrapper api. in case: write wrapper catches exceptions , translates them in normal return values. way coders can't forget catch normal-case-exceptions (because wrapper not throw them), , if put wrapper in own library might able use exception policy inside wrapper api. quick example getgroup problem:

    //myapiwrapper.h  namespace myapiwrapper {    class group;    class user {   public:     boost::optional<group> getgroup();   };  }   //myapiwrapper.cpp  #include "oddapi.h"  namespace myapiwrapper {    boost::optional<group> user::getgroup()   {     boost::optional<group> thegroup;      try {       oddapi::user& odduser= unwrap(*this);       oddapi::group& oddgroup = odduser.get_group();       thegroup = wrap(oddgroup);     }     catch(oddapi::exception&) {     }      return thegroup;   } } 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -