RuntimeException源码 5C

throw new RuntimeException("Stub!");
几乎所有的android源码实现都有throw new RuntimeException("Stub!");这么一段代码,
我在自学android,发现看不太懂,举个简单的例子
public boolean startActivityIfNeeded(Intent intent, int requestCode) {
throw new RuntimeException("Stub!");
}
这个方法的返回值为boolean,是怎么返回的呢?

7个回答

Stub顾名思义,就是桩的意思。表示这个方法先写上,但是没有实际的功能。这个函数也不会返回,因为会引发异常。

我们有两种实现软件的方法,一个是先进行顶层设计,然后再具体实现。另一个是先设计细节,然后把它们组合在一起成为整体。桩代码在软件设计的时候很常见,它就是第一种设计方式的体现,函数调用先写出来,同时编写一个桩,这个桩只是为了让编译通过。
丢出异常的目的是当实际要调用它的时候,防止设计者遗忘,丢出异常很明显提醒调用者,这个代码没有实现。

If a new activity was launched then true is returned; otherwise false is returned and you must handle the Intent yourself.

提示调用者该功能尚未实现,Stub只是留了个接口,并未真正实现功能。

RuntimeException属于运行异常,抛出来所以调用它的函数就不需要处理异常了。

抛异常后下面就不执行了,,所以没写返回值

你这个方法 是方法定义的时候要就返回一个Boolean的结果,但是当程序进去执行的时候,就发现了一个异常,就会跳出程序,这个程序,就完了。所以
这个程序如果想返回Boolean型结果,就要再异常前面返回,这个程序是一个不完整的程序,要求返回但还没有写返回语句

你这个方法 是方法定义的时候要就返回一个Boolean的结果,但是当程序进去执行的时候,就发现了一个异常,就会跳出程序,这个程序,就完了。所以
这个程序如果想返回Boolean型结果,就要再异常前面返回,这个程序是一个不完整的程序,要求返回但还没有写返回语句

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
RuntimeException
一些常见的运行时异常,一些常见的运行时异常,一些常见的运行时异常,
RunTimeException
RunTimeException 和普通的rnException 的区别是什么啊 ??
RuntimeException类
Java学习视频教程,该课程主要讲解JavaSE的发展历史,JDK开发环境的搭建,java api、JDK、面向对象编程、多线程、IO、类集、网络、数据库编程。
TimedOutException 不是一个RuntimeException??什么是RuntimeException????
如题
Java异常机制简述、RuntimeException与非RuntimeException的区别
Java中所有的异常都由Throwable继承而来,从而分为Error与Exception两类 Error 在Java中,Error层次的错误一般都比较严重,属于系统内部错误或者是资源错误,一旦程序出现这种错误,用户是没有能力去解决的,系统也只能告知用户出现了这种错误,并尽量安全的使程序终止。比如 当用户定义了一个 int[] num = new int[10000000000]; 如此大的整型...
很多RuntimeException
java.lang.RuntimeException: Unable to start activity ComponentInfo rnjava.lang.RuntimeException: Unable to instantiate activity ComponentInforn%d can't format java.lang.String argumentsrnrn當我login後,就彈main_activity stoppedrnmain_activity.javarn[code=Java]rn......extends TabActivityrnpublic void onCreate(Bundle savedInstanceState) rn super.onCreate(savedInstanceState);rn setContentView(R.layout.main);rn TabHost tabHost = getTabHost(); rn TabHost.TabSpec spec; rn Intent intent; rn intent = new Intent().setClass(this, FirstActivity.class); rn spec = tabHost.newTabSpec("Display").setIndicator("Display") rn .setContent(intent); rn tabHost.addTab(spec); rn[/code]rnrnFirstActivity.javarn[code=Java]rnpublic class FirstActivity extends Activity implements OnClickListener rn SQLiteDatabase db;rnString sql;rnString dataStr = String.format("%4s %15s %3d\n", "ProductCode", "ProductName", "Quantity_in_shop");rnCursor cursor = null;rnRadioButton rbName,rbCode,rbAsc,rbDesc;rnString[] columns = "ProductCode", "ProductName", "Quantity_in_shop";rnButton btnShow;rnTextView tvdata;rnrnrn @Override rn protected void onCreate(Bundle savedInstanceState) rn // TODO Auto-generated method stub rn super.onCreate(savedInstanceState); rn setContentView(R.layout.tab); rn rbName = (RadioButton) findViewById(R.id.rbName);rn rbCode = (RadioButton) findViewById(R.id.rbCode);rn rbAsc = (RadioButton) findViewById(R.id.rbAsc);rn rbDesc = (RadioButton) findViewById(R.id.rbDesc);rn btnShow = (Button) findViewById(R.id.btnshow);rn tvdata = (TextView) findViewById(R.id.tvdata);rn btnShow.setOnClickListener(this);rn rn rn rn try rn // Create a database if it does not existrn db = SQLiteDatabase.openDatabase("/data/data/com.android/eBidDB", null, SQLiteDatabase.CREATE_IF_NECESSARY);rnrn sql = "DROP TABLE IF EXISTS Product;";rn db.execSQL(sql);rnrn sql = "CREATE TABLE Product (ProductCode char PRIMARY KEY, ProductName char, Quantity_in_shop int);";rn db.execSQL(sql);rnrn db.execSQL("INSERT INTO Product(ProductCode, ProductName,Quantity_in_shop) values"rn + "('prod01', 'Orange Juice',200); ");rn db.execSQL("INSERT INTO Product(ProductCode, ProductName,Quantity_in_shop) values"rn + "('prod02', 'Milk',250); ");rn db.execSQL("INSERT INTO Product(ProductCode, ProductName,Quantity_in_shop) values"rn + "('prod03', 'Apple Juice',150); ");rn db.execSQL("INSERT INTO Product(ProductCode, ProductName,Quantity_in_shop) values"rn + "('prod04', 'Ice Tea',100); ");rn db.execSQL("INSERT INTO Product(ProductCode, ProductName,Quantity_in_shop) values"rn + "('prod05', 'Mineral Water',300); ");rn rn rn catch (SQLiteException e) rn //Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();rn rn rn public void onClick(View v) rn if (v.equals(btnShow)) rn String sortBy = (rbName.isChecked()) ? "ProductCode " : "ProductName ";rn String order = (rbAsc.isChecked()) ? "ASC" : "DESC";rnrn try rn db = SQLiteDatabase.openDatabase("/data/data/com.android/eBidDB", null, SQLiteDatabase.OPEN_READONLY);rn cursor = db.query("Product", columns, null, null, null, null, sortBy + order);rn dataStr = "";;rn while (cursor.moveToNext()) rn String PCode = cursor.getString(cursor.getColumnIndex("ProductCode"));rn String PName = cursor.getString(cursor.getColumnIndex("ProductName"));rn int PQ = cursor.getInt(cursor.getColumnIndex("Quantity_in_shop"));rn dataStr += String.format("%4s %15s %3d\n", PCode, PName, PQ);rn rn tvdata.setText(dataStr);rn rn db.close();rn cursor.close();rn catch (Exception e) rn //Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();rn rn rn rn rn rn rn rn[/code]rn[code=Java]rn rn rn rn rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrn[/code]rn
android layout抛出runtimeexception
实在搞不明白,求指教啊rnrn布局代码贴出来rn```rnrnrn rn rn rn rn rn rn rnrnrnrn rn rn rn rnrnrn rn rn```rnrn打印的异常栈:rn```rn 09-13 10:12:38.216 18008-18008/com.seedxyx.noteinfingers E/AndroidRuntime﹕ FATAL EXCEPTION: mainrn java.lang.RuntimeException: Unable to start activity ComponentInfocom.seedxyx.noteinfingers/com.seedxyx.noteinfingers.activity.OnePageAty: android.view.InflateException: Binary XML file line #21: Error inflating class android.widget.ScrollViewrn at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2067)rn at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2092)rn at android.app.ActivityThread.access$600(ActivityThread.java:133)rn at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)rn at android.os.Handler.dispatchMessage(Handler.java:99)rn at android.os.Looper.loop(Looper.java:137)rn at android.app.ActivityThread.main(ActivityThread.java:4794)rn at java.lang.reflect.Method.invokeNative(Native Method)rn at java.lang.reflect.Method.invoke(Method.java:511)rn at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)rn at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)rn at dalvik.system.NativeStart.main(Native Method)rn Caused by: android.view.InflateException: Binary XML file line #21: Error inflating class android.widget.ScrollViewrn at android.view.LayoutInflater.createView(LayoutInflater.java:613)rn at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)rn at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)rn at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)rn at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)rn at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)rn at android.view.LayoutInflater.inflate(LayoutInflater.java:489)rn at android.view.LayoutInflater.inflate(LayoutInflater.java:396)rn at android.view.LayoutInflater.inflate(LayoutInflater.java:352)rn at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)rn at android.app.Activity.setContentView(Activity.java:1867)rn at com.seedxyx.noteinfingers.activity.OnePageAty.onCreate(OnePageAty.java:92)rn at android.app.Activity.performCreate(Activity.java:5008)rn at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)rn at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2031)rn at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2092)rn at android.app.ActivityThread.access$600(ActivityThread.java:133)rn at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)rn at android.os.Handler.dispatchMessage(Handler.java:99)rn at android.os.Looper.loop(Looper.java:137)rn at android.app.ActivityThread.main(ActivityThread.java:4794)rn at java.lang.reflect.Method.invokeNative(Native Method)rn at java.lang.reflect.Method.invoke(Method.java:511)rn at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)rn at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)rn at dalvik.system.NativeStart.main(Native Method)rn Caused by: java.lang.reflect.InvocationTargetExceptionrn at java.lang.reflect.Constructor.constructNative(Native Method)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:417)rn at android.view.LayoutInflater.createView(LayoutInflater.java:587)rn at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)rn at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)rn at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)rn at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)rn at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)rn at android.view.LayoutInflater.inflate(LayoutInflater.java:489)rn at android.view.LayoutInflater.inflate(LayoutInflater.java:396)rn at android.view.LayoutInflater.inflate(LayoutInflater.java:352)rn at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)rn at android.app.Activity.setContentView(Activity.java:1867)rn at com.seedxyx.noteinfingers.activity.OnePageAty.onCreate(OnePageAty.java:92)rn at android.app.Activity.performCreate(Activity.java:5008)rn at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)rn at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2031)rn at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2092)rn at android.app.ActivityThread.access$600(ActivityThread.java:133)rn at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)rn at android.os.Handler.dispatchMessage(Handler.java:99)rn at android.os.Looper.loop(Looper.java:137)rn at android.app.ActivityThread.main(ActivityThread.java:4794)rn at java.lang.reflect.Method.invokeNative(Native Method)rn at java.lang.reflect.Method.invoke(Method.java:511)rn at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)rn at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)rn at dalvik.system.NativeStart.main(Native Method)rn Caused by: java.lang.OutOfMemoryErrorrn at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)rn at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:500)rn at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:353)rn at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)rn at android.content.res.Resources.loadDrawable(Resources.java:2007)rn at android.content.res.TypedArray.getDrawable(TypedArray.java:601)rn at android.view.View.(View.java:3336)rn at android.view.ViewGroup.(ViewGroup.java:427)rn at android.widget.FrameLayout.(FrameLayout.java:101)rn at android.widget.ScrollView.(ScrollView.java:158)rn at android.widget.ScrollView.(ScrollView.java:154)rn at java.lang.reflect.Constructor.constructNative(Native Method)rn at java.lang.reflect.Constructor.newInstance(Constructor.java:417)rn at android.view.LayoutInflater.createView(LayoutInflater.java:587)rn at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)rn at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)rn at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)rn at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)rn at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)rn at android.view.LayoutInflater.inflate(LayoutInflater.java:489)rn at android.view.LayoutInflater.inflate(LayoutInflater.java:396)rn at android.view.LayoutInflater.inflate(LayoutInflater.java:352)rn at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)rn at android.app.Activity.setContentView(Activity.java:1867)rn at com.seedxyx.noteinfingers.activity.OnePageAty.onCreate(OnePageAty.java:92)rn at android.app.Activity.performCreate(Activity.java:5008)rn at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)rn at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2031)rn at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2092)rn at android.app.ActivityThread.access$600(ActivityThread.java:133)rn at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1203)rn at android.os.Handler.dispatchMessage(Handler.java:99)rn at android.os.Looper.loop(Looper.java:137)rn at android.app.ActivityThread.main(ActivityThread.java:4794)rn at java.lang.reflect.Method.invokeNative(Native Method)rn at java.lang.reflect.Method.invoke(Method.java:511)rn at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)rn at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)rn at dalvik.system.NativeStart.main(Native Method)rn```rnrn在xml中没有报错啊,运行时在加载这个acvivity时就进不去了.....rnrn
JAVA——运行时异常(RuntimeException)
Exception中有一个特殊的子类异常RuntimeException运行时异常。 如果在函数内抛出该异常,函数上可以不用声明,编译一样通过。 如果在函数上声明了该异常。调用者可以不用进行处理。编译一样通过。之所以不用在函数上声明,是因为不需要让调用者处理。 当该异常发生,希望程序停止,因为在运行时,出现了无法继续运算的情况,希望停止程序后,对代码进行修正。 自定义异常时:如果该异常的发生
RunTimeException 在Java中的异常处理
RunTimeException报错问题 解决方案 总结: 要时常看清JAR包的使用情况
runtimeexception和exception有什么区别
看了几本书不同解释。但是还是不能掌握其中要义。特地发问n
(36)RuntimeException和创建自定义的RuntimeException子异常类和一些例子
一、Exception中有一个特殊的子类异常Runtime运行时异常。 ①如果在函数内部抛出该异常,函数上可以不用声明,编译一样通过。 ②如果在函数上声明了该异常,调用者可以不用进行处理,编译一样通过。 之所以不用再函数上声明,是因为不需要让调用者处理。 当该异常发生,希望程序停止,因为在运行时,出现了无法继续运算的情况,希望停止程序后,对代码修正 ①举个栗子 函数定义的没有问题,
写出常见的5个RuntimeException
ArithmeticException, 算术异常 ClassNotFoundException  类没找到时,抛出该异常 FileNotFoundException, 文件未找到异常 SQLException, 操作数据库异常 NullPointerException, 空指针异常...
RuntimeException 能不能被捕获?
如题。
求解:关于RuntimeException的理解
控制台能打印的Exception是不是就是RuntimeException?rn但是好像ClassNotFoundException在RuntimeException的子类里面没有,rn真的是不知道该怎么理解rn
java自定义异常(runtimeException)
                    Throwable                      /                \              Error             Exception                 /                   /               \         xxxxxx             xxxxxx  ...
几种常见的RuntimeException例子
public class ExceptionTest { public static void main(String[] args) { //常见的RuntimeException //1.ArithmeticException()运算异常 //2.ClassCastException()类的转换异常 //3.NullPointerException()空指针异常 //4.
为何RuntimeException不需要捕获
  从逻辑的角度来说,checked exceptions和runtime exception是有不同的使用目的的。checked exception用来指示一种调用方能够直接处理的异常情况。而runtime exception则用来指示一种调用方本身无法处理或恢复的程序错误。  checked exception迫使你捕获它并处理这种异常情况。以java.net.URL类的构建器(constru...
自定义运行时异常设计(RuntimeException)
RuntimeException
RuntimeException的抽象子类
最近遇到一个奇怪问题,如果一个类 AException 继承了RuntimeException, 然后另一个类BException 继承了AException,那么BException类型的变量 be, 执行be instanceof RuntimeException 会返回true。 这个道理很显然。rnrn但是如果AException是一个抽象类的话, 在执行be instanceof RuntimeException操作的时候,编译器会直接提示"Incompatible conditional operand types BException and RuntimeException"rnrn请问哪位高手能解答一下~
runtimeException也是能够捕获的
如题, 运行结果: bbb abcdef @Test public void testRuntimeException() { int a = 0; try { aaa333(); } catch (Exception ex) { System.out.println("bbb"); } Sy
RuntimeException和Error的处理
1、一般情况下,我们只对"被检查型"异常在程序中进行抛出或者处理?rnrn2、但是,当我们写一个程序,当其发生"运行时异常"或者"系统级错误"的时候,我们怎样处理?rnrn3、JAVA在对上述问题处理的时候,一般是在控制台显示错误信息,但是我希望可以弹出一个消息rnrn框,告诉用户发生了什么,并且安全的退出应用程序.该怎么做?
关于 throw new runtimeexception
在catch中throw new runtimeexception有什么好处?当抛了这个异常方法为何不用写返回值了
得到了RunTimeException异常
我的LogCat报出异常:rnrn java.lang.RunTimeException: Unable to instantiate activity ComponentInfocom.erikbalen.idealgaslawcalculator/com.erikbalen.idealgaslawcalculator.NumberActivity: java.lang.NullPointerExceptionrn at android.app.ActivityThread.performLaunchActivityActivityThread.java:2121rnrnjava文件如下:rnrn public class NumberActivity extends Activity rn EditText pressure = (EditText) findViewById(R.id.editTextPressure);rn EditText temperature = (EditText) findViewById(R.id.editTextTemperature);rn EditText volume = (EditText) findViewById(R.id.editTextVolume);rn TextView answer = (TextView) findViewById(R.id.textViewSolve);rn Button solve = (Button) findViewById(R.id.buttonSolve); rn @Overridern protected void onCreate(Bundle savedInstanceState) rn super.onCreate(savedInstanceState);rn setContentView(R.layout.activity_number);rn solve.setOnClickListener(new View.OnClickListener() rn @Overridern public void onClick(View v) rn double pressureValue = Double.parseDouble(pressure.getText().toString());rn double temperatureValue = Double.parseDouble(temperature.getText().toString());rn double volumeValue = Double.parseDouble(volume.getText().toString());rn double r = 0.0821;rn double answerValue = (pressureValue*volumeValue)/(r*temperatureValue);rn answer.setText(Double.toString(answerValue));rn rn );rn rn rnrn请高手帮忙,谢谢。
RuntimeException和非RuntimeException的区别, who can tell me ??
如题,50分!!rn各位出手啊!!呵呵
一个奇怪的runtimeException
import java.io.*;rnpublic class TestTransForm1 rn public static void main(String[] args)rn FileReader fr = null;rn BufferedReader br = new BufferedReader(fr);rn rn try rn fr = new FileReader("d:/java/1.txt");rn catch (FileNotFoundException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rn String str = null;rn rn try rn while((str=br.readLine())!=null)rn System.out.println(str);rn rn rn br.close();rn rn fr.close();rn catch (IOException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rnrnrn报错:Exception in thread "main" java.lang.NullPointerExceptionrn at java.io.Reader.(Unknown Source)rn at java.io.BufferedReader.(Unknown Source)rn at java.io.BufferedReader.(Unknown Source)rn at TestTransForm1.main(TestTransForm1.java:5)rn文件有内容,而且同样的程序我有时候执行就没问题,请问这种情况问题是出在哪里了?
exception和runtimeException的区别???
请问exception和runtimeException的区别rn
自定义异常(Exception)和运行时异常(RuntimeException )
自定义异常,运行时异常都可以定义提示指定信息 //自定义异常 package com.certus.util.httpClient; public class HttpClientException extends Exception{ /** * */ private static final long serialVersionUID = 1L; ...
自定义异常--继承RuntimeException
1、在实际的项目中,我们需要跟业务相关的异常,javaAPI中是没有的,所以我们要自定义package cn.tx.array;public class StockException extends RuntimeException{public StockException(){ super(); } public StockException(String mes ,Throwable c
【面试】四个比较常见的RuntimeException
对于下面这个测试类:     package cn.com.domain; public class Test { public static void main(String[] args) { //除0异常 java.lang.ArithmeticException: / by zero try { int a = 3/0; } catch (Exc...
IOException 与 RuntimeException,答案为什么不一样?
Question 71rnGiven: rn11.classA rn12. public void process() rn System.out.print(“A,”) rn13. class B extends A rn14. public void process() throws IOException rn15. super.process();rn16. System.out.print(“B,”)rn17. throw new IOException(); rn18. rn19. public static void main(String[] args) rn rn20. try new B().process(); rn21. catch (IOException e) System.out.println(“Exception”) rnWhat is the result? rnA. Exception rnB. A,B,Exception rnC. Compilation fails because of an error in line 20. rnD. Compilation fails because of an error in line 14. rnE. A NullPointerException is thrown at runtime. rnAnswer: D rnQuestion 72rnGiven: rn11.classA rn rn12. public void process() System.out.print(“A “) rn13. class B extends A rn14. public void process() throws RuntimeException rn15. super.process(); rn16. if (true) throw new RuntimeException(); rn17. System.out.print(“B”)rn rn18. public static void main(String[] args) rn19. try ((A)new B()).process(); rn20. catch (Exception e) System.out.print(“Exception “) rn21. rnWhat is the result? rnrnA. Exception rnB. A Exception rnC. A Exception B rnD. A B Exception rnE. Compilation fails because of an error in line 14. rnF. Compilation fails because of an error in line 19. rnAnswer: Brnrn这两道题好像啊,只是IOException与RuntimeException的区别,为什么会这样呢?请路过的神仙哥哥姐姐给小弟好好解释一下好吗?谢谢。。rn
不能抛出RuntimeException类型的异常
public class RuntimeException rnrn private static void throwit() throws Exceptionrn rn System.out.print("throwit ");rn //throw new Exception();rn throw new RuntimeException(); /* eclipse中提示这句代码有误,给出的错误提示是“No exception of type RuntimeException can be thrown; an exception type must be a subclass of Throwable” */rn rn rn public static void main(String[] args) rn rn tryrn rn System.out.print("try ");rn throwit();rn rn catch(Exception e)rn rn System.out.print("catch ");rn rn finallyrn rn System.out.print("finally ");rn rn System.out.println("last");rn rnrnrn上述程序中,代码 throw new RuntimeException(); 在 eclipse中提示这句代码有误,给出的错误提示是“No exception of type RuntimeException can be thrown; an exception type must be a subclass of Throwable” rn网上查看到可以抛出RuntimeException类型的异常,到我这怎么就出错了,求高手解答,谢谢!
关于RuntimeException运行时异常的一个小问题。。。
刚看到自定义异常的新手。。。。rn看到RuntimeException异常的时候,表明这个是运行时异常,一旦出现RuntimeException及其子类异常直接程序终止,就尝试打了个小程序rnclass Test extends RuntimeExceptionrnrn Test(String msg)rn rn super(msg);rn rnrnrnclass Demornrn int div(int a,int b) //运行时异常不需要在函数上进行异常声明rn rn if(b==0)rn throw new Test ("aaaaaaa");rn return a/b;rn rnrnclass new1rnrn public static void main(String[] args)rn rn Demo f = new Demo();rn tryrn rn System.out.println(f.div(4,0));rn rn catch (Test e)rn rn System.out.println(e.getMessage());rn rnrnrn System.out.println("ssssssssss");rn rnrnrn结果输出的时候,末尾的ssssss也输出来了。。。那么程序不就没有终止吗?rn还是说,RuntimeException没有一旦异常直接终止这个特性吗?。。。。rn新人求教。。。。。。。。。。。OTZ
MemcachedUtil get时候报RuntimeException
[code=java]rn java.lang.RuntimeException: Unable to find proto buffer classrn at com.google.protobuf.GeneratedMessageLite$SerializedForm.readResolve(GeneratedMessageLite.java:775)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at java.io.ObjectStreamClass.invokeReadResolve(ObjectStreamClass.java:1056)rn at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1765)rn at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1326)rn at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)rn at com.schooner.MemCached.ObjectTransCoder.decode(Unknown Source)rn at com.schooner.MemCached.AscIIClient.get(Unknown Source)rn at com.schooner.MemCached.AscIIClient.get(Unknown Source)rn at com.schooner.MemCached.AscIIClient.get(Unknown Source)rn at com.danga.MemCached.MemCachedClient.get(Unknown Source)rn at com.limboworks.lib.biz.util.JavaMemcachedUtil.get(JavaMemcachedUtil.java:106)rn at test.com.soccer.biz.util.TestMemcachedUtil.main(TestMemcachedUtil.java:38)rnCaused by: java.lang.ClassNotFoundException: com.soccer.biz.protocol.MsgProtos$MsgResrn at java.net.URLClassLoader$1.run(URLClassLoader.java:202)rn at java.security.AccessController.doPrivileged(Native Method)rn at java.net.URLClassLoader.findClass(URLClassLoader.java:190)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:306)rn at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)rn at java.lang.ClassLoader.loadClass(ClassLoader.java:247)rn at java.lang.Class.forName0(Native Method)rn at java.lang.Class.forName(Class.java:171)rn at com.google.protobuf.GeneratedMessageLite$SerializedForm.readResolve(GeneratedMessageLite.java:768)rn ... 15 morern[/code]rn[code=java]rnpublic static void main(String[] args) rn MemcachedUtil memcachedUtil = new JavaMemcachedUtil();rn memcachedUtil.setServer("192.168.1.201:11211");rn memcachedUtil.setWeight("3");rn try rn memcachedUtil.init();rn catch (Exception e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn String key = "MSG_10012";rn System.out.println(memcachedUtil.get(key));rnrn[/code]rn这是初始化的时候,奇怪的是我在另一个项目里面复制过来的,原项目里的可以正常获取,而我新项目里的有数据时就报了上面的错误,两个项目里的MemcachedUtil 和JavaMemcachedUtil都一样,就是包名不一样
[Eclipse]IDE如何提示RuntimeException?
如果是非RuntimeException,Eclipse会自动提示,要么抛出,要么thr。rnrn那么对于RuntimeException呢? 我想thr,如果让他自动生成代码框架。
try catch finally 与RuntimeException 的问题
有如下的语句rn1. public class X rn2. public static void main(String [] args) rn3. try rn4. badMethod();rn5. System.out.print(“A”);rn310 - 035rnLeading the way in IT testing and certification tools, www.testking.comrn-23 -rn6. rn7. catch (Exception ex) rn8. System.out.print(“B”);rn9. rn10. finally rn11. System.out.print(“C”);rn12. rn13. System.out.print(“D”);rn14. rn15. public static void badMethod() rn16. throw new RuntimeException();rn17. rn18. rn结果是BCD,我想不通的是当有异常发生时,程序是从finally处结束,但是这里为何会执行System.out.print(“D”)?
常见的RuntimeException异常有哪些?
RuntimeException是Exception类的子类,Exception类对象是Java程序处理或抛弃的对象,它有各种不同的子类分别对应于不同类型的例外。其中类RuntimeException代表运行时由Java虚拟机生成的例外,如算术运算异常 ArithmeticException(例如除以 0)、数组索引越界异常ArrayIndexOutOfBoundsException等;其他则为非...
常见的运行时异常(RuntimeException) 和复制中的异常处理
空指针异常: NullPointerException 数组下标越界异常:ArrayIndexOutOfBoundsException 字符串下标越界异常:StringIndexOutOfBoundsException 不合法的参数异常:IllegalArgumentException 算术异常:ArithmeticException 数字格式化异常:NumberFormatExcept...
JAVA Exception和RuntimeException的区别和用法、用处
JAVA Exception和RuntimeException的区别和用法、用处 记得以前刚学JAVA时候,不知道Exception和RuntimeException怎么用,直至今天在项目中遇到问题,才豁然开朗。故写下心得体会,当然也未必完全正确,仅仅个人理解。 ①Exception, 非运行时异常,在项目运行之前必须处理掉。一般由程序员try catch 掉。 ②RuntimeEx
很好奇的问下,runtimeexception是怎么做到的?
自定义的异常类怎么样做才能让编译器不强制捕获呢
各位大侠,请问runtimeException和非runtimeException的区别,详细些的啊~~我头大了两个星期~
各位大侠,请问runtimeException和非runtimeException的区别,详细些的啊~~我头大了两个星期~
相关热词 c# 标准差 计算 c#siki第五季 c#入门推荐书 c# 解码海康数据流 c# xml的遍历循环 c# 取 查看源码没有的 c#解决高并发 委托 c#日期转化为字符串 c# 显示问号 c# 字典对象池