标签: runtimeexception

C++中Java的IllegalArgumentException的等价物

在Java中,如果方法的输入参数无效,我们可以抛出一个IllegalArgumentException(类型为RuntimeException).在C++中,没有检查和未检查异常的概念.标准C++中是否有类似的异常可用于指示运行时异常?或者是否有一种不符合标准的共同风格,但每个人都在实践中遵循这样的情况?

或者,我应该创建自己的自定义异常并抛出它吗?

c++ java validation illegal-input runtimeexception

24
推荐指数
1
解决办法
1万
查看次数

运行时/已检查/未检查/错误/异常之间的差异

什么是运行时异常以及什么是已检查/未检查异常以及错误/异常之间的区别.为什么这么多类型?相反,Java可能只是遵循一个简单的设计(只是尝试/捕获所有类型)来处理程序中的异常情况?

java exception-handling exception runtimeexception checked-exceptions

23
推荐指数
2
解决办法
2万
查看次数

是否可以捕获除运行时异常之外的所有异常?

我有一个声明会抛出大量已检查的异常.我可以为所有这些添加所有catch块,如下所示:

try {
    methodThrowingALotOfDifferentExceptions();
} catch(IOException ex) {
    throw new MyCustomInitializationException("Class Resolver could not be initialized.", ex);
} catch(ClassCastException ex) {
    throw new MyCustomInitializationException("Class Resolver could not be initialized.", ex);
} catch...
Run Code Online (Sandbox Code Playgroud)

我不喜欢这样,因为它们都是以相同的方式处理的,所以有一些代码重复,还有很多代码要编写.相反可以抓住Exception:

try {
    methodThrowingALotOfDifferentExceptions();
} catch(Exception ex) {
    throw new MyCustomInitializationException("Class Resolver could not be initialized.", ex);
}
Run Code Online (Sandbox Code Playgroud)

那没关系,除了我希望所有运行时异常都被抛弃而不被捕获.这有什么解决方案吗?我当时认为要捕获的异常类型的一些聪明的通用声明可能会起作用(或者可能不是).

java generics exception try-catch runtimeexception

21
推荐指数
2
解决办法
8902
查看次数

android.app.ActivityThread.performLaunchActivity中的java.lang.RuntimeException

来自Google Play控制台, java.lang.RuntimeException不会出现" 由以下原因引起: "

以下日志是从Google Play控制台崩溃日志中复制的.
适用于:Android 8.0,Android 8.1,Android 7.0,Android 7.1

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2955)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3030)
  at android.app.ActivityThread.-wrap11 (Unknown Source)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1696)
  at android.os.Handler.dispatchMessage (Handler.java:105)
  at android.os.Looper.loop (Looper.java:164)
  at android.app.ActivityThread.main (ActivityThread.java:6938)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
Run Code Online (Sandbox Code Playgroud)

请帮我解决这个问题!

android runtimeexception

21
推荐指数
1
解决办法
1717
查看次数

RuntimeException和错误

在异常层次结构中,后代RuntimeExceptionError运行时异常/错误的后代 .

两者之间的区别在于:那些RuntimeException是由编程/设计不良引起的那些,以及那些Error不能/不应该由开发人员控制的那些.

例如,为了在应用程序中编写异常,在业务逻辑中发生某些事件时抛出异常,RuntimeException就会扩展.

问题是,扩展RuntimeException和扩展之间究竟有什么区别 Error- 除了扩展 Error是不好的做法?

java runtime-error runtimeexception

20
推荐指数
2
解决办法
2万
查看次数

在Java中处理RuntimeExceptions

任何人都可以解释如何处理Java中的运行时异常?

java exception-handling runtimeexception

19
推荐指数
1
解决办法
6万
查看次数

为什么运行时异常是未经检查的异常?

通常,如果任何类扩展Exception,它将成为检查异常.Runtime exception还扩展了Exception.那怎么回事unchecked exception

对于这种特殊情况,它们是否有自定义检入编译器

编辑: 我对检查v/s未经检查的异常和他们的优点和cos等有正确的想法.我没有他们在答案之间的差异.

java exception runtimeexception

19
推荐指数
2
解决办法
6165
查看次数

如何解决这个java.lang.RuntimeException?

Google Developer Console显示我的应用在过去一个月内收到了两个相同的错误,但这RuntimeException并未指定错误源自的类或文件.我没有具体的具体内容.以下是两个不同设备的错误:

三星Galaxy S8 Active(cruiserlteatt),4096MB RAM,Android 7.0第1页,共2页

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2984)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3045)
  at android.app.ActivityThread.handleRelaunchActivity 
(ActivityThread.java:4978)
  at android.app.ActivityThread.-wrap21 (ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1648)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:154)
  at android.app.ActivityThread.main (ActivityThread.java:6781)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run 
(ZygoteInit.java:1520)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1410)
Run Code Online (Sandbox Code Playgroud)

三星Galaxy S7(heroqltespr),4096MB RAM,Android 7.0报告2 of 2

java.lang.RuntimeException: 
  at android.app.ActivityThread.performLaunchActivity 
(ActivityThread.java:2947)
  at android.app.ActivityThread.handleLaunchActivity 
(ActivityThread.java:3008)
  at android.app.ActivityThread.handleRelaunchActivity 
(ActivityThread.java:4974)
  at android.app.ActivityThread.-wrap21 (ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1656)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:154)
  at android.app.ActivityThread.main (ActivityThread.java:6688)
  at java.lang.reflect.Method.invoke (Native Method) …
Run Code Online (Sandbox Code Playgroud)

java android runtimeexception

19
推荐指数
1
解决办法
4100
查看次数

正确使用RuntimeException?

可能重复:
在Java中,何时应该创建已检查的异常,何时应该是运行时异常?

我什么时候应该从中派生例外RuntimeException而不是Exception

A RuntimeException不必在方法的throws子句中声明,这可能是好的,因为它不必特别列出或坏,因为显式声明方法的异常是一种好习惯.

思考?

java exception runtimeexception

18
推荐指数
2
解决办法
3万
查看次数

自定义通知:java.lang.RuntimeException:错误的数组长度

我想利用谷歌的样品用在我的Android应用程序的自定义通知这里(部分创建自定义通知布局).由于我使用了这个确切的代码,我RuntimeException每隔几次就会收到通知.

我的堆栈跟踪:

FATAL EXCEPTION: main
java.lang.RuntimeException: bad array lengths
    at android.os.Parcel.readIntArray(Parcel.java:677)
    at android.app.INotificationManager$Stub$Proxy.enqueueNotificationWithTag(INotificationManager.java:369)
    at android.app.NotificationManager.notify(NotificationManager.java:110)
    at android.app.NotificationManager.notify(NotificationManager.java:90)
    at com.****.service.UpdateFeedService.notifyUpdateProgress(UpdateFeedService.java:266)
    at com.****.service.task.PodcastUpdaterTask.onProgressUpdate(PodcastUpdaterTask.java:63)
    at com.****.service.task.PodcastUpdaterTask.onProgressUpdate(PodcastUpdaterTask.java:1)
    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:432)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:144)
    at android.app.ActivityThread.main(ActivityThread.java:4937)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)

我的代码:

private final Intent updateInProgressIntent = new Intent(this.context, PodcastListActivity.class);
private RemoteViews updateInProgressContentView = null;
private PendingIntent updateInProgressPendingIntent = null;
private Notification updateInProgressNotification = null;
...
    @Override 
    public void onCreate() { 
        super.onCreate(); …
Run Code Online (Sandbox Code Playgroud)

notifications android runtimeexception

17
推荐指数
2
解决办法
9392
查看次数