Translates HDFS specific Exceptions to Pravega-equivalent Exceptions.

@param segmentName Name of the stream segment on which the exception occurs.
@param e           The exception to be translated.
@return  The exception to be thrown.
501890
static <T> StreamSegmentException convertException(String segmentName, Throwable e) {
        if (e instanceof RemoteException) {
            e = ((RemoteException) e).unwrapRemoteException();
        }

        if (e instanceof PathNotFoundException || e instanceof FileNotFoundException) {
            return new StreamSegmentNotExistsException(segmentName, e);
        } else if (e instanceof FileAlreadyExistsException || e instanceof AlreadyBeingCreatedException) {
            return new StreamSegmentExistsException(segmentName, e);
        } else if (e instanceof AclException) {
            return new StreamSegmentSealedException(segmentName, e);
        } else {
            throw Exceptions.sneakyThrow(e);
        }
    }
1019690
public static FileNotFoundException getFileNotFoundException(
      String bucketName, String objectName) {
    checkArgument(!isNullOrEmpty(bucketName), "bucketName must not be null or empty");
    return new FileNotFoundException(
        String.format(
            "Item not found: '%s'."
                + " If you enabled STRICT generation consistency, it is possible that"
                + " the live version is still available but the intended generation is deleted.",
            StorageResourceId.createReadableString(bucketName, nullToEmpty(objectName))));
  }
1114296
public PersistException toPersistException(Throwable e) {
        PersistException pe = transformIntoPersistException(e);
        if (pe != null) {
            return pe;
        }

        Throwable cause = e.getCause();
        if (cause != null) {
            pe = transformIntoPersistException(cause);
            if (pe != null) {
                return pe;
            }
        } else {
            cause = e;
        }

        return new PersistException(cause);
    }
437354
static InstallException create(Exception e) {
        if (e instanceof ProductInfoParseException) {
            ProductInfoParseException pipe = (ProductInfoParseException) e;
            String missingKey = pipe.getMissingKey();
            if (missingKey != null) {
                return create(Messages.UTILITY_MESSAGES.getLogMessage("version.missing.key", missingKey, pipe.getFile().getAbsoluteFile()));
            }
            return create(Messages.UTILITY_MESSAGES.getLogMessage("ERROR_UNABLE_READ_FILE", pipe.getFile().getAbsoluteFile(),
                                                                  pipe.getCause().getMessage()));
        }
        if (e instanceof DuplicateProductInfoException) {
            DuplicateProductInfoException dpie = (DuplicateProductInfoException) e;
            return create(Messages.UTILITY_MESSAGES.getLogMessage("version.duplicated.productId", ProductInfo.COM_IBM_WEBSPHERE_PRODUCTID_KEY,
                                                                  dpie.getProductInfo1().getFile().getAbsoluteFile(),
                                                                  dpie.getProductInfo2().getFile().getAbsoluteFile()));
        }
        if (e instanceof ProductInfoReplaceException) {
            ProductInfoReplaceException pire = (ProductInfoReplaceException) e;
            ProductInfo productInfo = pire.getProductInfo();
            String replacesId = productInfo.getReplacesId();
            if (replacesId.equals(productInfo.getId())) {
                return create(Messages.UTILITY_MESSAGES.getLogMessage("version.replaced.product.can.not.itself", productInfo.getFile().getAbsoluteFile()));
            }
            return create(Messages.UTILITY_MESSAGES.getLogMessage("version.replaced.product.not.exist", replacesId,
                                                                  productInfo.getFile().getAbsoluteFile()));
        }
        if (e instanceof RepositoryBackendIOException) {
            return create((RepositoryException) e, new Throwable(e), (RestRepositoryConnectionProxy) null, true);
        }
        return create(e.getMessage(), e, InstallException.RUNTIME_EXCEPTION);
    }
479263
private void exception(Throwable e)
    {
        try
        {
            _persistent=false;
            int error_code=HttpResponse.__500_Internal_Server_Error;
            
            if (e instanceof HttpException)
            {
                error_code=((HttpException)e).getCode();
                
                if (_request==null)
                    log.warn(e.toString());
                else
                    log.warn(_request.getRequestLine()+" "+e.toString());
                log.debug(LogSupport.EXCEPTION,e);
            }
            else if (e instanceof EOFException)
            {
                LogSupport.ignore(log,e);
                return;
            }
            else
            {
                _request.setAttribute("javax.servlet.error.exception_type",e.getClass());
                _request.setAttribute("javax.servlet.error.exception",e);
                
                if (_request==null)
                    log.warn(LogSupport.EXCEPTION,e);
                else
                    log.warn(_request.getRequestLine(),e);
            }
            
            if (_response != null && !_response.isCommitted())
            {
                _response.reset();
                _response.removeField(HttpFields.__TransferEncoding);
                _response.setField(HttpFields.__Connection,HttpFields.__Close);
                _response.sendError(error_code);
            }
        }
        catch(Exception ex)
        {
            LogSupport.ignore(log,ex);
        }
    }
853089
public <T> Exception onError(HystrixInvokable<T> commandInstance, FailureType failureType, Exception e) {
        return e; //by default, just pass through
    }
1252435
protected SofaRpcException convertToRpcException(InvocationTargetException e) {
        SofaRpcException exception;
        Throwable ie = e.getCause(); // 包装的原因
        if (ie != null) {
            Throwable realException = ie.getCause(); // 真正的原因
            if (realException != null) {
                if (realException instanceof SocketTimeoutException) {
                    exception = new SofaRpcException(RpcErrorType.CLIENT_TIMEOUT, "Client read timeout!", realException);
                } else if (realException instanceof ConnectException) {
                    open = false;
                    exception = new SofaRpcException(RpcErrorType.CLIENT_NETWORK,
                        "Connect to remote " + transportConfig.getProviderInfo()
                            + " error!", realException);
                } else {
                    exception = new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR,
                        "Send message to remote catch error: " + realException.getMessage(), realException);
                }
            } else {
                exception = new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR,
                    "Send message to remote catch error: " + ie.getMessage(), ie);
            }
        } else {
            exception = new SofaRpcException(RpcErrorType.CLIENT_UNDECLARED_ERROR,
                "Send message to remote catch error: " + e.getMessage(), e);
        }
        return exception;
    }
60982
public static EncodingException createEncodingException(
			final ErrorKeys errorId, final String message, final Exception e)
	{

		return new EncodingException(errorId.toString() + ":\r\n" + message, e);
	}
1121081
public final void setUncheckedLocalException(Throwable ex) throws EJBException {
        ExceptionMappingStrategy exceptionStrategy = getExceptionMappingStrategy();
        Throwable mappedException = exceptionStrategy.setUncheckedException(this, ex);
        if (mappedException != null) {
            if (mappedException instanceof EJBException) {
                throw (EJBException) mappedException;
            } else if (mappedException instanceof RuntimeException) {
                throw (RuntimeException) mappedException;
            } else if (mappedException instanceof Error) {
                throw (Error) mappedException;
            } else {
                // Unless there is a defect in mapping strategy, this should
                // never happen.  But if it does, we are going to
                // wrap what is returned with a EJBException. This is added
                // measure to ensure we do not break applications that
                // existed prior to EJB 3.
                if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                    Tr.event(tc, "unexpected Throwable returned by exception mapping strategy", new Object[] { mappedException, exceptionStrategy });
                }
                throw ExceptionUtil.EJBException(mappedException);
            }
        }
    }
723156
public static function translate(\Exception $e): \Exception
    {
        if ($e instanceof \MongoDB\Driver\Exception\ConnectionException ||
                $e instanceof \MongoDB\Driver\Exception\ExecutionTimeoutException) {
            return new \Caridea\Dao\Exception\Unreachable("System unreachable or connection timed out", $e->getCode(), $e);
        } elseif ($e instanceof \MongoDB\Driver\Exception\InvalidArgumentException ||
                $e instanceof \MongoDB\Driver\Exception\LogicException ||
                $e instanceof \MongoDB\Exception\BadMethodCallException) {
            return new \Caridea\Dao\Exception\Inoperable("Invalid API usage", $e->getCode(), $e);
        } elseif ($e instanceof \MongoDB\GridFS\Exception\FileNotFoundException ||
                $e instanceof \MongoDB\GridFS\Exception\CorruptFileException) {
            return new \Caridea\Dao\Exception\Unretrievable("Data could not be retrieved", $e->getCode(), $e);
        } elseif ($e instanceof \MongoDB\Driver\Exception\RuntimeException &&
                ($e->getCode() == 11000 || 'E11000' == substr($e->getMessage(), 0, 6))) {
            return new \Caridea\Dao\Exception\Duplicative("Unique constraint violation", 409, $e);
        } elseif ($e instanceof \MongoDB\Driver\Exception\BulkWriteException &&
                $e->getMessage() == 'Document failed validation') {
            return new \Caridea\Dao\Exception\Violating("Constraint violation", 422, $e);
        }
        return new \Caridea\Dao\Exception\Generic("Uncategorized database error", 0, $e);
    }
759278
static DatastoreException translateAndThrow(RetryHelperException ex) {
    BaseServiceException.translate(ex);
    throw new DatastoreException(UNKNOWN_CODE, ex.getMessage(), null, ex.getCause());
  }
161797
public static final RuntimeException convertException(Exception ex) {
        if (ex instanceof RuntimeException) {
            return (RuntimeException) ex;
        }
        return new ExceptionConverter(ex);
    }
693044
public SQLException exceptionWithQuery(ByteBuffer buffer, SQLException sqlEx,
      boolean explicitClosed) {
    if (options.dumpQueriesOnException || sqlEx.getErrorCode() == 1064 || explicitClosed) {
      return exceptionWithQuery(subQuery(buffer), sqlEx, explicitClosed);
    }
    return sqlEx;
  }
1367632
public void readFile(String filename) throws ConverterException {
        try {
            content = "";
            final InputStream input = ResourceManager.getInputStream(filename);
            while (input.available() > 0) {
                content = content + (char) input.read();
            }
            input.close();
        } catch (Exception e) {
            throw new ConverterException(e);
        }
    }
447767
public void seg(File input, File output) throws Exception{
        Utils.seg(input, output, isRemoveStopWord(), segmentation.getSegmentationAlgorithm(), word -> statistics(word, 1, statisticsMap));
    }
373927
public RuntimeException handleException(final Exception e) {
        log.error(e.getMessage(), e);
        if (e instanceof RuntimeException && EnvUtil.isPortableType(e.getClass()) ) {
            return (RuntimeException) e;
        }
        return new GenericPortableException( e.getMessage(), e );
    }
1017449
private boolean isJsonProcessingException(Exception e) {
        // Unfortunately Jackson doesn't have specific subclasses for each parse exception, so we have to use the
        // more brittle approach of checking the exception message.
        return e instanceof JsonProcessingException &&
                !(e instanceof JsonParseException &&
                    e.getMessage() != null &&
                    e.getMessage().startsWith("Unexpected end-of-input"));
    }