# safely

inline suspend fun < T > safely (noinline onException: ExceptionHandler < T > = defaultSafelyExceptionHandler, noinline block: suspend CoroutineScope.() -> T ): T (source)

It will run block inside of supervisorScope to avoid problems with catching of exceptions

Priorities of ExceptionHandlers:

- onException In case if custom (will be used anyway if not defaultSafelyExceptionHandler)

- CoroutineContext.get with SafelyExceptionHandlerKey as key

- defaultSafelyExceptionHandler

Remember, that ExceptionHandler from CoroutineContext.get will be used anyway if it is available. After it will be called onException

#### Parameters

onException

Will be called when happen exception inside of block. By default will throw exception - this exception will be available for catching

#### See also

defaultSafelyExceptionHandler
safelyWithoutExceptions
safelyWithContextExceptionHandler