<divclass="platform-hinted "data-platform-hinted="data-platform-hinted"><divclass="content sourceset-dependent-content"data-active=""data-togglable=":micro_utils.dokka:dokkaHtml/commonMain"><divclass="symbol monospace"><spanclass="token keyword">suspend </span><spanclass="token keyword">fun </span><spanclass="token operator"><</span><spanclass="token keyword"></span><ahref="safely-with-context-exception-handler.html">T</a><spanclass="token operator">></span><ahref="safely-with-context-exception-handler.html"><spanclass="token function">safelyWithContextExceptionHandler</span></a><spanclass="token punctuation">(</span><spanclass="parameters "><spanclass="parameter ">contextExceptionHandler<spanclass="token operator">: </span><ahref="-exception-handler/index.html">ExceptionHandler</a><spanclass="token operator"><</span><spanclass="token keyword"></span><ahref="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html">Unit</a><spanclass="token operator">></span><spanclass="token punctuation">, </span></span><spanclass="parameter ">safelyExceptionHandler<spanclass="token operator">: </span><ahref="-exception-handler/index.html">ExceptionHandler</a><spanclass="token operator"><</span><spanclass="token keyword"></span><ahref="safely-with-context-exception-handler.html">T</a><spanclass="token operator">></span><spanclass="token operator"> = </span>defaultSafelyExceptionHandler<spanclass="token punctuation">, </span></span><spanclass="parameter ">block<spanclass="token operator">: </span><spanclass="token keyword">suspend </span><spanclass="token keyword"></span><spandata-unresolved-link="kotlinx.coroutines/CoroutineScope///PointingToDeclaration/">CoroutineScope</span><spanclass="token punctuation">.</span><spanclass="token punctuation">(</span><spanclass="token punctuation">)</span><spanclass="token operator"> -></span><spanclass="token keyword"></span><ahref="safely-with-context-exception-handler.html">T</a></span></span><spanclass="token punctuation">)</span><spanclass="token operator">: </span><ahref="safely-with-context-exception-handler.html">T</a><spanclass="clearfix"><spanclass="floating-right">(<ahref="https://github.com/InsanusMokrassar/MicroUtils/blob/master//coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/HandleSafely.kt#L64">source</a>)</span></span></div><pclass="paragraph">This method will set new <ahref="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/index.html">coroutineContext</a> with <ahref="-context-safely-exception-handler/index.html">ContextSafelyExceptionHandler</a>. In case if <ahref="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/index.html">coroutineContext</a> already contains <ahref="-context-safely-exception-handler/index.html">ContextSafelyExceptionHandler</a>, <ahref="-context-safely-exception-handler/handler.html">ContextSafelyExceptionHandler.handler</a> will be used BEFORE <ahref="safely-with-context-exception-handler.html">contextExceptionHandler</a> in case of exception.</p><pclass="paragraph">After all, will be called <spandata-unresolved-link="kotlinx.coroutines//withContext/#kotlin.coroutines.CoroutineContext#kotlin.coroutines.SuspendFunction1[kotlinx.coroutines.CoroutineScope,TypeParam(bounds=[kotlin.Any?])]/PointingToDeclaration/">withContext</span> method with created <ahref="-context-safely-exception-handler/index.html">ContextSafelyExceptionHandler</a> and block which will call <ahref="safely.html">safely</a> method with <ahref="safely-with-context-exception-handler.html">safelyExceptionHandler</a> as onException parameter and <ahref="safely-with-context-exception-handler.html">block</a> as execution block</p></div></div>