为什么 Java ME 没有异常处理程序?
我正在寻找 Java 平台之间的差异,我注意到 J2ME 没有异常处理程序。
是什么让 try-catch 如此繁重以至于 Sun 没有将它们包含在 Java ME 中?
I was looking for the differences between Java platforms and i noticed that J2ME does not have exception handlers.
What makes try-catch so heavy that Sun did not include them in Java ME?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您正在谈论异常处理程序,例如由
Thread.setUncaughtExceptionHandler
,那么原因很简单:所有当前的 Java ME 版本都基于相当旧的 Java SE 版本(1.3、我想,但不要引用我的确切版本)。而该 Java SE 版本根本没有该功能,因此在本例中他们没有“删除”Java ME 中的任何内容。
另请注意,通过使用捕获所有异常并根据需要进行处理的
Runnable
启动Thread
来轻松模拟这些处理程序,因此它们不是不可替代的 API 元素。If you're talking about exception handlers such as set by
Thread.setUncaughtExceptionHandler
, then the reason is simple:All current Java ME versions are based on pretty old Java SE versions (1.3, I think, but don't quote me on that exact version). And that Java SE version simply didn't have that feature, so they didn't "remove" anything in Java ME in this instance.
Note, also, that those handlers are easily emulated by starting your
Thread
with aRunnable
that catches all exceptions and handles them as desired, so they are not an irreplaceable API element.