<divclass="content sourceset-dependent-content"data-active=""data-togglable=":micro_utils.dokka:dokkaHtml/jvmMain"><divclass="symbol monospace"><spanclass="token keyword">suspend </span><spanclass="token keyword">fun </span><spanclass="token operator"><</span><spanclass="token keyword"></span><ahref="[jvm]safely-with-context-exception-handler.html">T</a><spanclass="token operator">></span><ahref="[jvm]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="index.html#-738983448%2FClasslikes%2F-1052446920">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="index.html#-738983448%2FClasslikes%2F-1052446920">ExceptionHandler</a><spanclass="token operator"><</span><spanclass="token keyword"></span><ahref="[jvm]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="[jvm]safely-with-context-exception-handler.html">T</a></span></span><spanclass="token punctuation">)</span><spanclass="token operator">: </span><ahref="[jvm]safely-with-context-exception-handler.html">T</a></div><pclass="paragraph">This method will set new <ahref="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/index.html">coroutineContext</a> with <ahref="[jvm]-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="[jvm]-context-safely-exception-handler/index.html">ContextSafelyExceptionHandler</a>, <ahref="[jvm]-context-safely-exception-handler/handler.html">ContextSafelyExceptionHandler.handler</a> will be used BEFORE <ahref="[jvm]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="[jvm]-context-safely-exception-handler/index.html">ContextSafelyExceptionHandler</a> and block which will call <ahref="[jvm]safely.html">safely</a> method with <ahref="[jvm]safely-with-context-exception-handler.html">safelyExceptionHandler</a> as onException parameter and <ahref="[jvm]safely-with-context-exception-handler.html">block</a> as execution block</p></div></div>