Create a synthetic {@link ApiException} for an individual entry. When the entire RPC fails, it
implies that all entries failed as well. This helper is used to make that behavior explicit.
The generated exception will have the overall error as its cause.
420178
private static ApiException createSyntheticErrorForRpcFailure(Throwable overallRequestError) {
    if (overallRequestError instanceof ApiException) {
      ApiException requestApiException = (ApiException) overallRequestError;

      return ApiExceptionFactory.createException(
          "Didn't receive a result for this mutation entry",
          overallRequestError,
          requestApiException.getStatusCode(),
          requestApiException.isRetryable());
    }

    return ApiExceptionFactory.createException(
        "Didn't receive a result for this mutation entry",
        overallRequestError,
        LOCAL_UNKNOWN_STATUS,
        false);
  }
189386
def extern_create_exception(self, context_handle, msg_ptr, msg_len):
    """"""
    c = self._ffi.from_handle(context_handle)
    msg = self.to_py_str(msg_ptr, msg_len)
    return c.to_value(Exception(msg))
221040
public static ErrorDescription create(ApplicationException ex) {
    	ErrorDescription description = new ErrorDescription();
    	description.setCategory(ex.getCategory());
    	description.setStatus(ex.getStatus());
    	description.setCode(ex.getCode());
    	description.setMessage(ex.getMessage());
    	description.setDetails(ex.getDetails());
    	description.setCorrelationId(ex.getCorrelationId());    	
    	description.setCause(ex.getCauseString());    	
    	description.setStackTrace(ex.getStackTraceString());    	
    	return description;
    }
1163337
protected IOException toIoException(Exception e) {
        if (e instanceof IOException) {
            return (IOException) e;
        } else {
            return new IOException("Unexpected failure", e);
        }
    }
813782
private Map<String, javax.ejb.ApplicationException> createApplicationExceptionMap(EJBJar ejbJar) {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "createApplicationExceptionMap : " + ejbJar);

        // Get List of ApplicationException objects and convert to a Map where
        // key is String name of exceptions class and value is the rollback
        // setting of the exception class from xml.
        // d541552, d541552.1 - Improve performance and footprint.  Returned
        //                      exceptionMap in MDO may be null (ie. the
        //                      map is only created when it is needed).
        if (ejbJar != null) {
            AssemblyDescriptor assemblyDescriptor = ejbJar.getAssemblyDescriptor();
            if (assemblyDescriptor != null) {
                List<ApplicationException> applicationExceptions = assemblyDescriptor.getApplicationExceptionList();
                if (!applicationExceptions.isEmpty()) {
                    Map<String, javax.ejb.ApplicationException> appExMap = new HashMap<String, javax.ejb.ApplicationException>(); // F743-14982
                    for (ApplicationException appEx : applicationExceptions) {
                        String className = appEx.getExceptionClassName();
                        appExMap.put(className, new ApplicationExceptionImpl(appEx.isRollback(), appEx.isInherited())); // F743-14982
                    }

                    if (isTraceOn && tc.isEntryEnabled())
                        Tr.exit(tc, "createApplicationExceptionMap : " + appExMap.size());

                    return appExMap;
                }
            }
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "createApplicationExceptionMap : null");

        return null;
    }
890971
public HttpResponseHandler<SdkBaseException> createErrorResponseHandler(
            JsonErrorResponseMetadata errorResponsMetadata) {
        return new ApiGatewayErrorResponseHandler(
                createErrorUnmarshallers(errorResponsMetadata.getErrorShapes().stream()),
                SdkStructuredPlainJsonFactory.JSON_FACTORY);
    }
1326072
private static Response createErrorResponse(Exception e, AlluxioConfiguration alluxioConf) {
    AlluxioStatusException se = AlluxioStatusException.fromThrowable(e);
    ErrorResponse response = new ErrorResponse(se.getStatus().getCode(), se.getMessage());

    Response.ResponseBuilder rb = Response.serverError().entity(response);
    if (alluxioConf.getBoolean(PropertyKey.WEBUI_CORS_ENABLED)) {
      return makeCORS(rb).build();
    }

    return rb.build();
  }
979045
public static Exception resolveRSBException(final RSBException rsbException) {
        Exception exception = null;

        // build stacktrace array where each line is stored as entry. entry is extract each line stacktrace into arr
        final String[] stacktrace = ("Caused by: " + rsbException.getMessage()).split("\n");

        // iterate in reverse order to build exception chain.
        for (int i = stacktrace.length - 1; i >= 0; i--) {
            try {
                // only parse cause lines containing the exception class and message.
                if (stacktrace[i].startsWith("Caused by:")) {
                    final String[] causes = stacktrace[i].split(":");
                    final String exceptionClassName = causes[1].substring(1);

                    // System.out.println("parse: " + stacktrace[i]);
                    // System.out.println("match: " + causes.length);

                    final String message = causes.length <= 2 ? "" : stacktrace[i].substring(stacktrace[i].lastIndexOf(exceptionClassName) + exceptionClassName.length() + 2).trim();

                    // detect exception class
                    final Class<Exception> exceptionClass;
                    try {
                        exceptionClass = (Class<Exception>) Class.forName(exceptionClassName);

                        // build exception
                        try {
                            // try default constructor
                            exception = exceptionClass.getConstructor(String.class, Throwable.class).newInstance(message, exception);
                        } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassCastException ex) {
                            try {
                                // try to handle missing fields
                                if (exception == null && message.isEmpty()) {
                                    exception = exceptionClass.getConstructor().newInstance();
                                } else if (exception == null && !message.isEmpty()) {
                                    exception = exceptionClass.getConstructor(String.class).newInstance(message);
                                } else if (exception != null && message.isEmpty()) {
                                    exception = exceptionClass.getConstructor(Throwable.class).newInstance(exception);
                                } else {
                                    throw ex;
                                }
                            } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException exx) {
                                throw new CouldNotPerformException("No compatible constructor found!", exx);
                            }
                        }
                        //System.out.println("create "+ exception.getClass().getSimpleName() + ":" + exception.getMessage());
                    } catch (ClassNotFoundException | ClassCastException | CouldNotPerformException ex) {
                        ExceptionPrinter.printHistory(new CouldNotPerformException("Exception[" + exceptionClassName + "] could not be recovered because no compatible Constructor(String, Throwable) was available!", ex), LOGGER, LogLevel.WARN);

                        // apply fallback solution
                        exception = new CouldNotPerformException(message, exception);
                    }
                }
            } catch (IndexOutOfBoundsException | NullPointerException ex) {
                ExceptionPrinter.printHistory(new CouldNotPerformException("Could not extract exception cause or message out of Line[" + stacktrace[i] + "]!", ex), LOGGER, LogLevel.WARN);
            }
        }
        return exception;
    }
1316130
public static CreateException fromThrowable(Throwable cause) {
    return (cause instanceof CreateException)
                   ? (CreateException) cause
                   : new CreateException(cause);
  }
581287
public static JSONObjectException fromUnexpectedIOE(IOException src)
    {
        return new JSONObjectException("Unexpected IOException (of type "
                +src.getClass().getName()+"): "+src.getMessage(), (JsonLocation)null, src);
    }
875738
public static LdapException create(LDAPException e) {
        return new LdapException(DefaultLdapResultCodeFactory.convertResultCode(e.getResultCode()),
                e.getDiagnosticMessage(), e);
    }
1326867
public static function createExceptionForResponse(
        array $allMessage,
        int $responseCode,
        string $responseId
    ): ApiException {
        $errorMessage = static::generateErrorMessage($responseCode, $allMessage, $responseId);

        switch ($responseCode) {
            case self::HTTP_RESPONSE_CODE_BAD_REQUEST:
                return new BadRequestException($errorMessage, $responseCode, $responseId);
            case self::HTTP_RESPONSE_CODE_UNAUTHORIZED:
                return new UnauthorizedException($errorMessage, $responseCode, $responseId);
            case self::HTTP_RESPONSE_CODE_FORBIDDEN:
                return new ForbiddenException($errorMessage, $responseCode, $responseId);
            case self::HTTP_RESPONSE_CODE_NOT_FOUND:
                return new NotFoundException($errorMessage, $responseCode, $responseId);
            case self::HTTP_RESPONSE_CODE_METHOD_NOT_ALLOWED:
                return new MethodNotAllowedException($errorMessage, $responseCode, $responseId);
            case self::HTTP_RESPONSE_CODE_TOO_MANY_REQUESTS:
                return new TooManyRequestsException($errorMessage, $responseCode, $responseId);
            case self::HTTP_RESPONSE_CODE_INTERNAL_SERVER_ERROR:
                return new PleaseContactBunqException($errorMessage, $responseCode, $responseId);
            default:
                return new UnknownApiErrorException($errorMessage, $responseCode, $responseId);
        }
    }
1374320
public static PagerDuty create(String apiKey, Retrofit retrofit) {
    checkStringArgument(apiKey, "apiKey");
    checkNotNull(retrofit, "retrofit");

    return realPagerDuty(apiKey, retrofit.create(EventService.class));
  }
1148708
public static IOException createCompositeException(Collection<IOException> innerExceptions) {
    checkArgument(
        innerExceptions != null && !innerExceptions.isEmpty(),
        "innerExceptions (%s) must be not null and contain at least one element", innerExceptions);

    Iterator<IOException> innerExceptionIterator = innerExceptions.iterator();

    if (innerExceptions.size() == 1) {
      return innerExceptionIterator.next();
    }

    IOException combined = new IOException("Multiple IOExceptions.");
    while (innerExceptionIterator.hasNext()) {
      combined.addSuppressed(innerExceptionIterator.next());
    }
    return combined;
  }
710108
protected static Throwable newEncoderException(final String message,
                                                   final Throwable cause) {

        try {
            return ENCODER_EXCEPTION
                .getConstructor(String.class, Throwable.class)
                .newInstance(message, cause);
        } catch (final NoSuchMethodException nsme) {
            throw new RuntimeException(nsme);
        } catch (final InstantiationException ie) {
            throw new RuntimeException(ie);
        } catch (final IllegalAccessException iae) {
            throw new RuntimeException(iae);
        } catch (final InvocationTargetException ite) {
            throw new RuntimeException(ite);
        }
    }
994197
private JsonRpcClientException createJsonRpcClientException(ObjectNode errorObject) {
		int code = errorObject.has(JsonRpcBasicServer.ERROR_CODE) ? errorObject.get(JsonRpcBasicServer.ERROR_CODE).asInt() : 0;
		return new JsonRpcClientException(code, errorObject.get(JsonRpcBasicServer.ERROR_MESSAGE).asText(), errorObject.get(JsonRpcBasicServer.DATA));
	}
877193
@Override
	public Object create(Object locator) throws CreateException {
		for (Registration registration : _registrations) {
			if (registration.getLocator().equals(locator)) {
				try {
					return registration.getFactory().create(locator);
				} catch (Exception ex) {
					if (ex instanceof CreateException)
						throw (CreateException) ex;

					throw (CreateException) new CreateException(null, "Failed to create object for " + locator)
							.withCause(ex);
				}
			}
		}
		return null;
	}