throwable

trap exceptions comprehensively in Jython

試著忘記壹切 提交于 2020-01-11 11:53:10
问题 This is my attempt so far to trap all exceptions in Jython code. The most difficult thing, I find, is trapping exceptions when you override a method from a Java class: with the "vigil" decorator below (which also tests whether the EDT/Event Despatch Thread status is correct) you can find out the first line where the code is thrown... so you can identify the method itself. But not the line. Furthermore, tracing stack frames back through Python and Java stacks is completely beyond me. Obviously

How to not throw a generically specified exception?

好久不见. 提交于 2020-01-01 01:16:10
问题 I created a "producer" interface (to be used with method references, respectively to be easily mocked for unit tests): @FunctionalInterface public interface Factory<R, T, X extends Throwable> { public R newInstanceFor(T t) throws X; } which I created like that, as my first use case actually had to throw some checked WhateverException . But my second use case doesn't have an X to throw. The best I could come up with to make the compiler happy is: Factory<SomeResultClass, SomeParameterClass,

why isn't java.lang.Throwable an abstract class?

社会主义新天地 提交于 2019-12-24 11:53:19
问题 Possible duplicate: why-is-java-lang-throwable-a-class Hi! I doesn't understand why Throwable isn't abstract class. I see only one use case for these: in logging systems for figure out call hierarchy. But it can be some static method for this or other class. So, why?) Thanks. upd from java.util.logging.LogRecord // Get the stack trace. StackTraceElement stack[] = (new Throwable()).getStackTrace(); Why it can't be Throwable.getStackTrace(); or as in java.lang.Thread (new Exception())

How can I fix 'No exception of type SomeException can be thrown; an exception type must be a subclass of Throwable'

妖精的绣舞 提交于 2019-12-24 02:08:27
问题 I have java webstart app and want to use app API for testing purposes. So I get required (as I assumed) library from webserver and install it to maven repository. And all is fine except custom exception which received No exception of type SomeException can be thrown; an exception type must be a subclass of Throwable As I understand from similar topics - some jar library is missing, is there some way to know which one? or maybe there is other way to fix this? (of course I can install all jars

Is it OK to catch Throwable for performing cleanup? [duplicate]

陌路散爱 提交于 2019-12-22 08:19:08
问题 This question already has answers here : Is it a bad practice to catch Throwable? (14 answers) Closed 5 years ago . Take an example like this: public List<CloseableThing> readThings(List<File> files) throws IOException { ImmutableList.Builder<CloseableThing> things = ImmutableList.builder(); try { for (File file : files) { things.add(readThing(file)) } return things.build(); } catch (Throwable t) { for (CloseableThing thing : things.build()) { thing.close(); } throw t; } } A code review

Catching Throwable in Blackberry Java: Good Idea?

南笙酒味 提交于 2019-12-20 06:45:51
问题 I often see catch clauses for Throwable in Blackberry documentation, such as the Network API docs. My sense is that this is not generally a good practice in Java. Is there a reason for this in Blackberry programming? Does it have to do with stack trace generation for Throwables? 回答1: When you catch Throwable in a BlackBerry app, not only does it preserve the stack trace, it saves that stack trace in the device event log. There is no way for an app to get a stack trace itself, so unfortunately

When should Throwable be used instead of new Exception?

不问归期 提交于 2019-12-17 06:05:13
问题 Given: Throwable is Exception 's superclass. When I read texts on writing your own 'exceptions', I see examples of Throwable being used in the catch block and other texts show new Exception() being used in the catch block. I have yet to see an explanation of when one should use each. My question is this, when should Throwable be used and when should new Exception() be used? Inside the catch or else block using either: throw throwable; or throw new Exception(); 回答1: (from comments) The issue

Difference between using Throwable and Exception in a try catch

China☆狼群 提交于 2019-12-17 04:37:21
问题 Sometimes I see try { } catch(Throwable e) { } And sometimes try { } catch(Exception e) { } What is the difference 回答1: By catching Throwable it includes things that subclass Error . You should generally not do that, except perhaps at the very highest "catch all" level of a thread where you want to log or otherwise handle absolutely everything that can go wrong. It would be more typical in a framework type application (for example an application server or a testing framework) where it can be

Exception handling : throw, throws and Throwable

我的未来我决定 提交于 2019-12-17 02:28:49
问题 Can any of you explain what the differences are between throw , throws and Throwable and when to use which? 回答1: throws : Used when writing methods, to declare that the method in question throws the specified (checked) exception. As opposed to checked exceptions, runtime exceptions (NullPointerExceptions etc) may be thrown without having the method declare throws NullPointerException . throw : Instruction to actually throw the exception. (Or more specifically, the Throwable ). The throw

Differences between Exception and Error

北城余情 提交于 2019-12-16 23:00:52
问题 I'm trying to learn more about basic Java and the different types of Throwables, can someone let me know the differences between Exceptions and Errors? 回答1: Errors should not be caught or handled (except in the rarest of cases). Exceptions are the bread and butter of exception handling. The Javadoc explains it well: An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. Look at a few