首页 \ 问答 \ 弄清楚可以抛出的所有可能的异常?(Figure out all possible exceptions that can be thrown?)

弄清楚可以抛出的所有可能的异常?(Figure out all possible exceptions that can be thrown?)

是否有可能找出可能抛出的所有可能的异常,这些异常不一定由方法的签名列出。

有2例

1)不必声明的运行时异常(显然有些是显而易见的,例如空指针,但是还有其他运行时异常我想要捕获,这可能是由于数据不好,在开发过程中我不喜欢还不知道数据不好。

2)异常是签名中列出的异常的子类。

动机的例子

想象一下我在HttpURLConnection对象上调用getInputStream(),它会抛出java.io.Exception,但实际上,它会抛出其他异常,这些异常是java.io.Exception(ala java.io.FileNotFoundException)的sublcasses,我想要的以独特的方式处理(即不想将所有java.io.Exceptions混为一谈)。

所以虽然我可以通过捕获java.io.Exception并打印出实际的异常,然后修改代码来处理这种情况,在实践中学习,但是想知道是否有更好的方法:)

谢谢

编辑:我认为人们错过了我的第二个问题。 抛出与方法签名完全一致的已检查异常的方法,但由于方法的签名仅具有某种基类,因此未在其中列出。


Is it possible to figure out all possible exceptions that can be thrown that are not necessarily listed by the method's signature.

There are 2 cases

1) runtime exceptions that don't have to be declared (obviously some are obvious, such as null pointer, but there are other runtime exceptions that I'd want to catch that can be due to bad data, which while in development I don't know is bad data yet).

2) exceptions that are subclasses of the exception listed in the signature.

a motivation example

imagine I call getInputStream() on an HttpURLConnection object, it throws java.io.Exception, but in reality, it throws other exceptions that are sublcasses of java.io.Exception (ala java.io.FileNotFoundException), which I'd want to handle in a unique manner (i.e. don't want to lump all java.io.Exceptions together).

so while I can learn in practice by catching java.io.Exception and printing out the actual exception, and then modifying code to handle that case, was wondering if there was a better method :)

thanks

edit: I think people are missing my 2nd problem. Methods that throw checked exceptions that are fully consistent with the method's signature, but aren't listed in it due to the method's signature only having some sort of base class.


原文:
更新时间:2022-03-23 07:03

最满意答案

Angular即将发生变化! 在官方Angular回购中查看此GitHub问题

TL; DR

什么是非常好的:有了角度4.1的第一个测试版(作为本周4.0.0的后续版本发布),您可以执行以下操作:

class MyCmp {


constructor(private _builder: AnimationBuilder) {
   }
   myMethod() {
      const animation = this._builder.build([
        style(...),
        animate(...),
        group([
          animate(...)
          animate(...)
          animate(...)
        ])
      ]);
      const player = animation.create(someElement);
      player.play();
   }
}

Changes are coming to Angular! See this GitHub issue in the official Angular repo.

TL;DR

What's really good: With the first beta of angular 4.1 (which comes out as the follow-up release to this weeks 4.0.0) you can do the following:

class MyCmp {


constructor(private _builder: AnimationBuilder) {
   }
   myMethod() {
      const animation = this._builder.build([
        style(...),
        animate(...),
        group([
          animate(...)
          animate(...)
          animate(...)
        ])
      ]);
      const player = animation.create(someElement);
      player.play();
   }
}

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。