Replaces old exceptions with new exceptions to be raised in their place.
545291
def replace_exceptions(
    old_to_new_exceptions: Dict[Type[BaseException], Type[BaseException]]
) -> Callable[..., Any]:
    
    old_exceptions = tuple(old_to_new_exceptions.keys())

    def decorator(to_wrap: Callable[..., Any]) -> Callable[..., Any]:
        @functools.wraps(to_wrap)
        # String type b/c pypy3 throws SegmentationFault with Iterable as arg on nested fn
        # Ignore so we don't have to import `Iterable`
        def wrapper(
            *args: Iterable[Any], **kwargs: Dict[str, Any]
        ) -> Callable[..., Any]:
            try:
                return to_wrap(*args, **kwargs)
            except old_exceptions as err:
                try:
                    raise old_to_new_exceptions[type(err)] from err
                except KeyError:
                    raise TypeError(
                        "could not look up new exception to use for %r" % err
                    ) from err

        return wrapper

    return decorator
923951
public void setExceptions(java.util.Collection<RootCauseException> exceptions) {
        if (exceptions == null) {
            this.exceptions = null;
            return;
        }

        this.exceptions = new java.util.ArrayList<RootCauseException>(exceptions);
    }
183047
public <X extends Exception> void replaceAll(Try.BiFunction<? super K, ? super V, ? extends V, X> function) throws X {
        List<K> keyToRemove = null;
        V newVal = null;

        for (Map.Entry<K, V> entry : valueMap.entrySet()) {
            newVal = function.apply(entry.getKey(), entry.getValue());

            if (N.isNullOrEmpty(newVal)) {
                if (keyToRemove == null) {
                    keyToRemove = new ArrayList<>();
                }

                keyToRemove.add(entry.getKey());
            } else {
                try {
                    entry.setValue(newVal);
                } catch (IllegalStateException ise) {
                    throw new ConcurrentModificationException(ise);
                }
            }
        }

        if (N.notNullOrEmpty(keyToRemove)) {
            for (K key : keyToRemove) {
                valueMap.remove(key);
            }
        }
    }
428281
def _newRemoteException(ErrorType):
    ''''''
    RemoteErrorBaseType = _RemoteExceptionMeta('', (ErrorType,), {})
    class RemoteException(RemoteErrorBaseType):
        BaseExceptionType = ErrorType

        def __init__(self, thrownError, tracebackString):
            self.thrownError = thrownError
            self.tracebackString = tracebackString
            RemoteErrorBaseType.__init__(self, *thrownError.args)

        loadError = staticmethod(_loadError)

        def __str__(self):
            return '\n%s\n%s' % (self.tracebackString, self.thrownError)

        def __reduce__(self):
            args = (ErrorType, self.thrownError, self.tracebackString)
            return self.loadError, args
    RemoteException.__name__ = 'Remote' + ErrorType.__name__
    return RemoteException
396981
def replace(self, target):
        
        if sys.version_info < (3, 3):
            raise NotImplementedError("replace() is only available "
                                      "with Python 3.3 and later")
        if self._closed:
            self._raise_closed()
        self._accessor.replace(self, target)
1247252
def replace_sys_args(new_args):
    
    # Replace sys.argv arguments
    # for module import
    old_args = sys.argv
    sys.argv = new_args
    try:
        yield
    finally:
        sys.argv = old_args
428944
def build_new_exception e
        e.class.new(e.message)
      rescue
        Exception.new e.message
      end
1355111
public void exceptionShift() {
        numExceptional++;
        double mag = 0.05 * numExceptional;
        if (mag > 1.0) mag = 1.0;

        double angle = 2.0 * UtilEjml.PI * (rand.nextDouble() - 0.5) * mag;
        performImplicitSingleStep(0, angle, true);

        // allow more convergence time
        nextExceptional = steps + exceptionalThresh;  // (numExceptional+1)*
    }
1147336
def try_except_handler(self, node):
        """"""
        # List all excepted exception's names
        excepted_types = []
        for handler in node.handlers:
            if handler.type is None:
                excepted_types = None
                break

            if isinstance(handler.type, ast.Tuple):
                excepted_types.extend([exception_type for exception_type
                                       in handler.type.elts])

            else:
                excepted_types.append(handler.type)

        new_exception_list = self.ignore_exceptions

        if self.ignore_exceptions is not None:
            if excepted_types is None:
                new_exception_list = None
            else:
                new_exception_list = list(set(excepted_types +
                                              self.ignore_exceptions))

        # Set the new ignore list, and save the old one
        old_exception_handlers, self.ignore_exceptions = \
            self.ignore_exceptions, new_exception_list

        # Run recursively on all sub nodes with the new ignore list
        node.body = [self.visit(node_item) for node_item in node.body]

        # Revert changes from ignore list
        self.ignore_exceptions = old_exception_handlers
202688
def raise_exception(self, node, exc=None, msg='', expr=None,
                        lineno=None):
        """"""
        if self.error is None:
            self.error = []
        if expr is None:
            expr = self.expr
        if len(self.error) > 0 and not isinstance(node, ast.Module):
            msg = '%s' % msg
        err = ExceptionHolder(node, exc=exc, msg=msg, expr=expr, lineno=lineno)
        self._interrupt = ast.Break()
        self.error.append(err)
        if self.error_msg is None:
            self.error_msg = "at expr='%s'" % (self.expr)
        elif len(msg) > 0:
            self.error_msg = msg
        if exc is None:
            try:
                exc = self.error[0].exc
            except:
                exc = RuntimeError
        raise exc(self.error_msg)
74211
public void reindexItems() {
    if (numUnsortedItems > 0) {
      int[] newSortedKeys = Arrays.copyOf(sortedKeys, sortedKeys.length + numUnsortedItems);
      int[] newSortedValues = Arrays.copyOf(sortedValues, sortedValues.length + numUnsortedItems);

      int oldLength = sortedKeys.length;
      for (int i = 0; i < numUnsortedItems; i++) {
        newSortedKeys[i + oldLength] = unsortedKeys[i];
        newSortedValues[i + oldLength] = unsortedValues[i];
      }

      ArrayUtils.sortKeyValuePairs(newSortedKeys, newSortedValues, 0, newSortedKeys.length);

      sortedKeys = newSortedKeys;
      sortedValues = newSortedValues;
      numUnsortedItems = 0;
      
      rebuildKeySet();
    }
  }
64673
public void replaceWithNewInstances(Collection<SSTableReader> toReplace, Collection<SSTableReader> replaceWith)
    {
        replaceReaders(toReplace, replaceWith, true);
    }
454730
def _raise_deferred_exc(self):
    """"""
    if self._deferred_exception:
      try:
        exc_type, exc_value, exc_traceback = self._deferred_exception
        raise_with_traceback(exc_value, exc_traceback)
      except TypeError:
        # If `_deferred_exception` isn't a 3-item tuple (raising a TypeError on the above
        # destructuring), treat it like a bare exception.
        raise self._deferred_exception
1318467
private void adaptHistories(int numberOfDeletions){
		for (int i = 0; i < numberOfDeletions; i++){
			SortedSet<Integer> keys = new TreeSet<>(this.predictionHistories.keySet());
			this.predictionHistories.remove(keys.first());
			keys = new TreeSet<>(this.predictionHistories.keySet());
			for (Integer key : keys){
				List<Integer> predHistory = this.predictionHistories.remove(key);
				this.predictionHistories.put(key-keys.first(), predHistory);
			}
		}
	}
191799
protected function prepareReplacements(Exception $exception)
    {
        $statusCode = $this->getStatusCode($exception);

        if (! $message = $exception->getMessage()) {
            $message = \sprintf('%d %s', $statusCode, Response::$statusTexts[$statusCode]);
        }

        $replacements = [
            ':message' => $message,
            ':status_code' => $statusCode,
        ];

        if ($exception instanceof MessageBagErrors && $exception->hasErrors()) {
            $replacements[':errors'] = $exception->getErrors();
        }

        if ($exception instanceof ValidationException) {
            $replacements[':errors'] = $exception->errors();
            $replacements[':status_code'] = $exception->status;
        }

        if ($code = $exception->getCode()) {
            $replacements[':code'] = $code;
        }

        if ($this->runningInDebugMode()) {
            $replacements[':debug'] = [
                'line' => $exception->getLine(),
                'file' => $exception->getFile(),
                'class' => \get_class($exception),
                'trace' => \explode("\n", $exception->getTraceAsString()),
            ];

            // Attach trace of previous exception, if exists
            if (! \is_null($exception->getPrevious())) {
                $currentTrace = $replacements[':debug']['trace'];

                $replacements[':debug']['trace'] = [
                    'previous' => \explode("\n", $exception->getPrevious()->getTraceAsString()),
                    'current' => $currentTrace,
                ];
            }
        }

        return \array_merge($replacements, $this->replacements);
    }
1037795
def exception_set(self, exception=None):
        
        if not exception:
            exception = sys.exc_info()
        self.exception = exception
        self.exception_raise = self._exception_raise
572705
def devaluate(actual_exception, expected_class, expected_message=nil)
      actual_message = actual_exception && actual_exception.message

      if !actual_exception
        pass new_message.raises_kind_of(expected_class)
      elsif !actual_exception.is_a?(expected_class)
        if expected_message && !(actual_message.to_s =~ %r[#{expected_message}])
          pass new_message.raises_kind_of(expected_class).
            with_message(expected_message)
        else
          pass new_message.raises_kind_of(expected_class)
        end
      else
        message = new_message.expected_to_not_raise_kind_of(expected_class)

        if expected_message
          fail message.with_message(expected_message).but.
            raised(actual_exception.class).
            with_message(actual_exception.message)
        else
          fail message
        end
      end
    end