⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 methodtroublereturns.java

📁 it contains the practical programs in our college
💻 JAVA
字号:
import java.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;public class MethodTroubleReturns {    private void drinkMe(int liters) {	if (liters < 0)	    throw new IllegalArgumentException("I can't drink a negative amount of liquid");    }    public static void main(String... args) {	try {	    MethodTroubleReturns mtr  = new MethodTroubleReturns(); 	    Class<?> c = mtr.getClass();   	    Method m = c.getDeclaredMethod("drinkMe", int.class);	    m.invoke(mtr, -1);        // production code should handle these exceptions more gracefully	} catch (InvocationTargetException x) {	    Throwable cause = x.getCause();	    System.err.format("drinkMe() failed: %s%n", cause.getMessage());	} catch (Exception x) {	    x.printStackTrace();	}    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -