Java Code Examples for java.lang.reflect.InvocationTargetException#getMessage()

The following examples show how to use java.lang.reflect.InvocationTargetException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogProxy.java    From clickhouse-jdbc with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    String msg =
        "Call class: " + object.getClass().getName() +
        "\nMethod: " + method.getName() +
        "\nObject: " + object +
        "\nArgs: " + Arrays.toString(args) +
        "\nInvoke result: ";
    try {
        final Object invokeResult = method.invoke(object, args);
        msg +=  invokeResult;
        return invokeResult;
    } catch (InvocationTargetException e) {
        msg += e.getMessage();
        throw e.getTargetException();
    } finally {
        msg = "==== ClickHouse JDBC trace begin ====\n" + msg + "\n==== ClickHouse JDBC trace end ====";
        log.trace(msg);
    }
}
 
Example 2
Source File: ExceptionHandler.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
protected void perform(InvocationTargetException e, Shell shell, String title, String message)
{
	Throwable target = e.getTargetException();
	if (target instanceof CoreException)
	{
		perform((CoreException) target, shell, title, message);
	}
	else
	{
		IdeLog.logError(FormatterUIEplPlugin.getDefault(), e, IDebugScopes.DEBUG);
		if (e.getMessage() != null && e.getMessage().length() > 0)
		{
			displayMessageDialog(e, e.getMessage(), shell, title, message);
		}
		else
		{
			displayMessageDialog(e, target.getMessage(), shell, title, message);
		}
	}
}
 
Example 3
Source File: MethodWrapper.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
public T callMethod(DataExtension extension, Parameters with) {
    if (disabled) return null;
    try {
        return returnType.cast(with.usingOn(extension, method));
    } catch (InvocationTargetException notReadyToBeCalled) {
        if (notReadyToBeCalled.getCause() instanceof NotReadyException) {
            return null; // Data or API not available to make the call.
        } else {
            throw new IllegalArgumentException(method.getDeclaringClass() + " method " + method.getName() + " could not be called: " + notReadyToBeCalled.getMessage(), notReadyToBeCalled);
        }
    } catch (IllegalAccessException e) {
        throw new IllegalArgumentException(method.getDeclaringClass() + " method " + method.getName() + " could not be called: " + e.getMessage(), e);
    }
}
 
Example 4
Source File: Bus.java    From SaveAndroidResources with MIT License 5 votes vote down vote up
/**
 * Throw a {@link RuntimeException} with given message and cause lifted from an {@link
 * InvocationTargetException}. If the specified {@link InvocationTargetException} does not have a
 * cause, neither will the {@link RuntimeException}.
 */
private static void throwRuntimeException(String msg, InvocationTargetException e) {
    Throwable cause = e.getCause();
    if (cause != null) {
        throw new RuntimeException(msg + ": " + cause.getMessage(), cause);
    } else {
        throw new RuntimeException(msg + ": " + e.getMessage(), e);
    }
}
 
Example 5
Source File: Bus.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
/**
 * Throw a {@link RuntimeException} with given message and cause lifted from an {@link
 * InvocationTargetException}. If the specified {@link InvocationTargetException} does not have a
 * cause, neither will the {@link RuntimeException}.
 */
private static void throwRuntimeException(String msg, InvocationTargetException e) {
  Throwable cause = e.getCause();
  if (cause != null) {
    throw new RuntimeException(msg + ": " + cause.getMessage(), cause);
  } else {
    throw new RuntimeException(msg + ": " + e.getMessage(), e);
  }
}
 
Example 6
Source File: JavaService.java    From jolie with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Object[] getArguments( final JavaOperation javaOperation, final CommMessage message )
	throws IllegalAccessException {
	if( javaOperation.parameterConstructor == null ) {
		return new Object[ 0 ];
	} else {
		try {
			return new Object[] { javaOperation.parameterConstructor.invoke( null, message.value() ) };
		} catch( InvocationTargetException e ) {
			throw new IllegalAccessException( e.getMessage() );
		}
	}
}
 
Example 7
Source File: Lax.java    From CPUSim with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Call all end tag methods in the handler list
 * @param qName the ending tag
 * @throws org.xml.sax.SAXException if something goes wrong when parsing
 */
public void endElement(String uri, String localName, String qName)
        throws SAXException
{
    int i;
    String sEndMethodName = "end" + qName;

    // Call every tag start method for this tag found in the list
    //of handlers.
    for (i = 0; i < _vecHandlers.size(); i++) {
        Object oThisHandler = _vecHandlers.elementAt(i);
        Method mEndMethod =
                mFindMethod(oThisHandler, sEndMethodName, _caNoArgs);
        if (mEndMethod != null) {
            try {
                mEndMethod.invoke(oThisHandler);
            } catch (InvocationTargetException ite) {
                //Note:  java.lang.reflect.InvocationTargetException.getMessage()
                //just returns the ite's message even if it is null.  So
                //in that case, we'll rewrap the target exception
                //in a SAXException.
                if (ite.getMessage() == null
                        && ite.getTargetException() != null
                        && ite.getTargetException() instanceof Exception)
                    throw new SAXException((Exception) ite.getTargetException());
                else
                    throw new SAXException(ite);
            } catch (Exception mre) {
                throw new SAXException(mre);
            }
        }
    }
    popTag();
}
 
Example 8
Source File: Bus.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * Throw a {@link RuntimeException} with given message and cause lifted from an {@link
 * InvocationTargetException}. If the specified {@link InvocationTargetException} does not have a
 * cause, neither will the {@link RuntimeException}.
 */
protected static void throwRuntimeException(String msg, InvocationTargetException e) {
  Throwable cause = e.getCause();
  if (cause != null) {
    throw new RuntimeException(msg + ": " + cause.getMessage(), cause);
  } else {
    throw new RuntimeException(msg + ": " + e.getMessage(), e);
  }
}
 
Example 9
Source File: ExceptionHandler.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void perform(InvocationTargetException e, Shell shell, String title, String message) {
	Throwable target= e.getTargetException();
	if (target instanceof CoreException) {
		perform((CoreException)target, shell, title, message);
	} else {
		JavaPlugin.log(e);
		if (e.getMessage() != null && e.getMessage().length() > 0) {
			displayMessageDialog(e.getMessage(), shell, title, message);
		} else {
			displayMessageDialog(target.getMessage(), shell, title, message);
		}
	}
}
 
Example 10
Source File: Bus.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * Throw a {@link RuntimeException} with given message and cause lifted from an {@link
 * InvocationTargetException}. If the specified {@link InvocationTargetException} does not have a
 * cause, neither will the {@link RuntimeException}.
 */
protected static void throwRuntimeException(String msg, InvocationTargetException e) {
  Throwable cause = e.getCause();
  if (cause != null) {
    throw new RuntimeException(msg + ": " + cause.getMessage(), cause);
  } else {
    throw new RuntimeException(msg + ": " + e.getMessage(), e);
  }
}
 
Example 11
Source File: Lax.java    From CPUSim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Handle an incoming block of text by calling the textOf method for the
 * current tag.
 */
public void characters(char[] caChars, int iStart, int iEnd)
        throws SAXException
{
    String sCurrentTag = sCurrentTag();

    if (sCurrentTag != null) {
        int i;
        String sTextMethodName = "textOf" + sCurrentTag;
        String sArg = null;

        // Call every text method for current tag found in the list
        //of handlers
        for (i = 0; i < _vecHandlers.size(); i++) {
            Object oThisHandler = _vecHandlers.elementAt(i);
            Method mTextMethod =
                    mFindMethod(oThisHandler, sTextMethodName, _caString);
            if (mTextMethod != null) {
                if (sArg == null) {
                    sArg = new String(caChars, iStart, iEnd);
                }
                try {
                    mTextMethod.invoke(oThisHandler, sArg);
                } catch (InvocationTargetException ite) {
                    //Note:  java.lang.reflect.InvocationTargetException.getMessage()
                    //just returns the ite's message even if it is null.  So
                    //in that case, we'll rewrap the target exception
                    //in a SAXException.
                    if (ite.getMessage() == null
                            && ite.getTargetException() != null
                            && ite.getTargetException() instanceof Exception)
                        throw new SAXException((Exception) ite.getTargetException());
                    else
                        throw new SAXException(ite);
                } catch (Exception mre) {
                    throw new SAXException(mre);
                }
            }
        }
    }
}
 
Example 12
Source File: Lax.java    From CPUSim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Call all start methods for this tag.
 * @param qName the start tag
 * @param alAttrs the attributes
 * @throws org.xml.sax.SAXException if something goes wrong
 */
public void startElement(String uri, String localName,
                         String qName, Attributes alAttrs)
        throws org.xml.sax.SAXException
{
    int i;
    String sStartMethodName = "start" + qName;

    pushTag(qName);

    // Call every tag start method for this tag found in the list of handlers.
    for (i = 0; i < _vecHandlers.size(); i++) {
        Object oThisHandler = _vecHandlers.elementAt(i);
        Method mStartMethod = mFindMethod(oThisHandler, sStartMethodName, _caAttrList);
        if (mStartMethod == null) {
            mStartMethod = mFindMethod(oThisHandler, sStartMethodName, _caNoArgs);
        }
        if (mStartMethod != null) {
            // Call start method with or without attribute list
            Class[] caMethodArgs = mStartMethod.getParameterTypes();
            try {
                if (caMethodArgs.length == 0) {
                    mStartMethod.invoke(oThisHandler);
                }
                else {
                    mStartMethod.invoke(oThisHandler, alAttrs);
                }
            } catch (InvocationTargetException ite) {
                //Note:  java.lang.reflect.InvocationTargetException.getMessage()
                //just returns the ite's message even if it is null.  So
                //in that case, we'll rewrap the target exception
                //in a SAXException.
                //ite.printStackTrace();
                if (ite.getMessage() == null
                        && ite.getTargetException() != null
                        && ite.getTargetException() instanceof Exception)
                    throw new SAXException((Exception) ite.getTargetException());
                else
                    throw new SAXException(ite);
            } catch (Exception mre) {
                throw new SAXException(mre);
            }
        }
    }
}
 
Example 13
Source File: ServerSession.java    From Tatala-RPC with Apache License 2.0 4 votes vote down vote up
private Object execute(TransferObject to) throws SocketExecuteException{
	Object retobj = null;
	
	try {
		String calleeClassName = to.getCalleeClass();
		String calleeMethod = to.getCalleeMethod();
		
		if(calleeClassName == null){
			throw new SocketExecuteException("No connection with client.");
		}
		
		//Check default proxy, don't need reflection.
		if(to.isDefaultCallee() || calleeClassName.equals(TransferObject.DEFAULT_PROXY)){
			if(defaultProxy != null){
				retobj = defaultProxy.execute(to);
			}
		} else {
			Class<?> calleeClass = null;
			Object calleeObject = null;
			
			if(calleeClassCache.containsKey(calleeClassName)){
				calleeClass = calleeClassCache.get(calleeClassName);
				calleeObject = calleeObjectCache.get(calleeClassName);
			} else {
				calleeClass = Class.forName(calleeClassName);
				calleeObject = calleeClass.newInstance();
				
				calleeClassCache.put(calleeClassName, calleeClass);
				calleeObjectCache.put(calleeClassName, calleeObject);
			}
			
			if(calleeClass == null || calleeObject == null){
				throw new SocketExecuteException("No connection with client.");
			}
			
			Method meth = calleeClass.getMethod(calleeMethod, TransferObject.class);
			retobj = meth.invoke(calleeObject, to);
		}
	} catch (InvocationTargetException ite) {
		if(ite.getCause() instanceof TatalaRollbackException){
			TatalaRollbackException tre = (TatalaRollbackException)ite.getCause();
			throw tre;
		} else {
			log.error("Server execute error e: " + ite, ite);
			throw new SocketExecuteException("Server execute error e: " + ite.getMessage());
		}

	} catch (Exception e) {
		log.error("Server execute error e: " + e, e);
		throw new SocketExecuteException("Server execute error e: " + e.getMessage());
	} 
	
	return retobj;
}
 
Example 14
Source File: ServerSession.java    From Tatala-RPC with Apache License 2.0 4 votes vote down vote up
private Object execute(TransferObject to) throws SocketExecuteException{
	Object retobj = null;
	
	try {
		String calleeClassName = to.getCalleeClass();
		String calleeMethod = to.getCalleeMethod();
		
		if(calleeClassName == null){
			throw new SocketExecuteException("No connection with client.");
		}
		
		//Check default proxy, don't need reflection.
		if(to.isDefaultCallee() || calleeClassName.equals(TransferObject.DEFAULT_PROXY)){
			if(defaultProxy != null){
				retobj = defaultProxy.execute(to);
			}
		} else {
			Class<?> calleeClass = null;
			Object calleeObject = null;
			
			if(calleeClassCache.containsKey(calleeClassName)){
				calleeClass = calleeClassCache.get(calleeClassName);
				calleeObject = calleeObjectCache.get(calleeClassName);
			} else {
				calleeClass = Class.forName(calleeClassName);
				calleeObject = calleeClass.newInstance();
				
				calleeClassCache.put(calleeClassName, calleeClass);
				calleeObjectCache.put(calleeClassName, calleeObject);
			}
			
			if(calleeClass == null || calleeObject == null){
				throw new SocketExecuteException("No connection with client.");
			}
			
			Method meth = calleeClass.getMethod(calleeMethod, TransferObject.class);
			retobj = meth.invoke(calleeObject, to);
		}
	} catch (InvocationTargetException ite) {
		if(ite.getCause() instanceof TatalaRollbackException){
			TatalaRollbackException tre = (TatalaRollbackException)ite.getCause();
			throw tre;
		} else {
			log.error("Server execute error e: " + ite, ite);
			throw new SocketExecuteException("Server execute error e: " + ite.getMessage());
		}

	} catch (Exception e) {
		log.error("Server execute error e: " + e, e);
		throw new SocketExecuteException("Server execute error e: " + e.getMessage());
	} 
	
	return retobj;
}
 
Example 15
Source File: ServerSession.java    From Tatala-RPC with Apache License 2.0 4 votes vote down vote up
private Object execute(TransferObject to) throws SocketExecuteException{
	Object retobj = null;
	
	try {
		String calleeClassName = to.getCalleeClass();
		String calleeMethod = to.getCalleeMethod();
		
		if(calleeClassName == null){
			throw new SocketExecuteException("No connection with client.");
		}
		
		//Check default proxy, don't need reflection.
		if(calleeClassName.equals(TransferObject.DEFAULT_PROXY)){
			if(defaultProxy != null){
				retobj = defaultProxy.execute(to);
			}
		} else {
			Class<?> calleeClass = null;
			Object calleeObject = null;
			
			if(calleeClassCache.containsKey(calleeClassName)){
				calleeClass = calleeClassCache.get(calleeClassName);
				calleeObject = calleeObjectCache.get(calleeClassName);
			} else {
				calleeClass = Class.forName(calleeClassName);
				calleeObject = calleeClass.newInstance();
				
				calleeClassCache.put(calleeClassName, calleeClass);
				calleeObjectCache.put(calleeClassName, calleeObject);
			}
			
			if(calleeClass == null || calleeObject == null){
				throw new SocketExecuteException("No connection with client.");
			}
			
			Method meth = calleeClass.getMethod(calleeMethod, TransferObject.class);
			retobj = meth.invoke(calleeObject, to);
		}
	} catch (InvocationTargetException ite) {
		if(ite.getCause() instanceof TatalaReturnException){
			TatalaReturnException tre = (TatalaReturnException)ite.getCause();
			throw tre;
		} else {
			log.error("Server execute error e: " + ite, ite);
			throw new SocketExecuteException("Server execute error e: " + ite.getMessage());
		}

	} catch (Exception e) {
		log.error("Server execute error e: " + e, e);
		throw new SocketExecuteException("Server execute error e: " + e.getMessage());
	} 
	
	return retobj;
}