示例#1
0
        private async ValueTask <Course> TryCatch(ReturningCourseFunction returningCourseFunction)
        {
            try
            {
                return(await returningCourseFunction());
            }
            catch (InvalidCourseInputException invalidCourseInputException)
            {
                throw CreateAndLogValidationException(invalidCourseInputException);
            }
            catch (NotFoundCourseException notFoundCourseException)
            {
                throw CreateAndLogValidationException(notFoundCourseException);
            }
            catch (SqlException sqlException)
            {
                throw CreateAndLogCriticalDependencyException(sqlException);
            }
            catch (DbUpdateConcurrencyException dbUpdateConcurrencyException)
            {
                var lockedCourseException = new LockedCourseException(dbUpdateConcurrencyException);

                throw CreateAndLogDependencyException(lockedCourseException);
            }
            catch (DbUpdateException dbUpdateException)
            {
                throw CreateAndLogDependencyException(dbUpdateException);
            }
            catch (Exception exception)
            {
                throw CreateAndLogServiceException(exception);
            }
        }
示例#2
0
        private async ValueTask <Course> TryCatch(ReturningCourseFunction returningCourseFunction)
        {
            try
            {
                return(await returningCourseFunction());
            }
            catch (NullCourseException nullCourseException)
            {
                throw CreateAndLogValidationException(nullCourseException);
            }
            catch (InvalidCourseException invalidCourseException)
            {
                throw CreateAndLogValidationException(invalidCourseException);
            }
            catch (NotFoundCourseException nullCourseException)
            {
                throw CreateAndLogValidationException(nullCourseException);
            }
            catch (SqlException sqlException)
            {
                throw CreateAndLogCriticalDependencyException(sqlException);
            }
            catch (DuplicateKeyException duplicateKeyException)
            {
                var alreadyExistsCourseException =
                    new AlreadyExistsCourseException(duplicateKeyException);

                throw CreateAndLogValidationException(alreadyExistsCourseException);
            }
            catch (DbUpdateConcurrencyException dbUpdateConcurrencyException)
            {
                var lockedCourseException = new LockedCourseException(dbUpdateConcurrencyException);

                throw CreateAndLogDependencyException(lockedCourseException);
            }
            catch (DbUpdateException dbUpdateException)
            {
                throw CreateAndLogDependencyException(dbUpdateException);
            }
            catch (Exception exception)
            {
                var failedCourseServiceException =
                    new FailedCourseServiceException(exception);

                throw CreateAndLogServiceException(failedCourseServiceException);
            }
        }