throwable

Is there a favored idiom for mimicing Java's try/finally in C++?

陌路散爱 提交于 2019-12-03 02:19:01
Been doing Java for number of years so haven't been tracking C++. Has finally clause been added to C++ exception handling in the language definition? Is there a favored idiom that mimics Java's try/finally? Am also bothered that C++ doesn't have an ultimate super type for all possible exceptions that could be thrown - like Java's Throwable class. I can write: try { // do something } catch(...) { // alas, can't examine the exception // can only do cleanup code and perhaps rethrow, ala: throw; } ADDENDUM EDIT: I ended up accepting the answer that had the most up votes, i.e., use destructors to

java.lang.Throwable: setStateLocked

ε祈祈猫儿з 提交于 2019-12-02 15:20:42
问题 Everytime from other Activity intents to LoginActivity, it will crashes the app. Logcat of the error: AccessibilityManager: setStateLocked: wasEnabled = false, mIsEnabled = false, wasTouchExplorationEnabled = false, mIsTouchExplorationEnabled = false, wasHighTextContrastEnabled = false, mIsHighTextContrastEnabled = false java.lang.Throwable: setStateLocked at com.example.feoit.mapmanagement.LoginActivity.onCreate(LoginActivity.java:63) public class LoginActivity extends AppCompatActivity

Catching Throwable in Blackberry Java: Good Idea?

允我心安 提交于 2019-12-02 12:39:54
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? Michael Donohue 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 you can't automatically collect stack traces. To view the stack trace, you pull up the

java.lang.Throwable: setStateLocked

与世无争的帅哥 提交于 2019-12-02 10:34:43
Everytime from other Activity intents to LoginActivity, it will crashes the app. Logcat of the error: AccessibilityManager: setStateLocked: wasEnabled = false, mIsEnabled = false, wasTouchExplorationEnabled = false, mIsTouchExplorationEnabled = false, wasHighTextContrastEnabled = false, mIsHighTextContrastEnabled = false java.lang.Throwable: setStateLocked at com.example.feoit.mapmanagement.LoginActivity.onCreate(LoginActivity.java:63) public class LoginActivity extends AppCompatActivity implements View.OnClickListener { EditText email, password; Button btnSignIn, forgotpwdbtn, btnRegister;

Which subclass of Throwable should be caught and which shouldn't?

时间秒杀一切 提交于 2019-11-29 07:45:50
API doc says never catch Throwable subclass Error which signifies abnormal behavior. Does it implies that the segregation between Error and Exception is to tell programmers that which subclass should be caught and which shouldn't ? Or there is more to it ? In general, Error is something seriously wrong (often within the platform itself ) which you could not conceivably handle. The only times I have ever cared about catching Error is in order to log it , following which I then re-throw. This is vitally important as it is easy to let errors (and runtime exceptions) propagate up the call stack in

Extending Throwable in Java

跟風遠走 提交于 2019-11-29 05:26:54
Java lets you create an entirely new subtype of Throwable , e.g: public class FlyingPig extends Throwable { ... } Now, very rarely , I may do something like this: throw new FlyingPig("Oink!"); and of course elsewhere: try { ... } catch (FlyingPig porky) { ... } My questions are: Is this a bad idea? And if so, why? What could've been done to prevent this subtyping if it is a bad idea? Since it's not preventable (as far as I know), what catastrophies could result? If this isn't such a bad idea, why not? How can you make something useful out of the fact that you can extends Throwable ? Proposed

Why doesn't Java support generic Throwables?

牧云@^-^@ 提交于 2019-11-28 21:13:59
class Bouncy<T> extends Throwable { } // Error: the generic class Bouncy<T> may not subclass java.lang.Throwable Why doesn't Java support generic Throwable s? I realize that type erasure complicates certain things, but obviously Java gets by with a lot already, so why not push it one more notch and allow generic Throwable s, with comprehensive compile-time check for potential problems? I feel like the type erasure argument is rather weak. Currently, we can't do: void process(List<String> list) { } void process(List<Integer> list) { } Of course, we get by without it. I'm not asking that we

What is the preferred Throwable to use in a private utility class constructor?

北慕城南 提交于 2019-11-28 21:11:38
Effective Java (Second Edition) , Item 4, discusses using private constructors to enforce noninstantiability. Here's the code sample from the book: public final class UtilityClass { private UtilityClass() { throw new AssertionError(); } } However, AssertionError doesn't seem like the right thing to throw. Nothing is being "asserted", which is how the API defines the use of AssertionError . Is there a different Throwable that's typically in this situation? Does one usually just throw a general Exception with a message? Or is it common to write a custom Exception for this? It's pretty trivial,

Which subclass of Throwable should be caught and which shouldn't?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 01:33:39
问题 API doc says never catch Throwable subclass Error which signifies abnormal behavior. Does it implies that the segregation between Error and Exception is to tell programmers that which subclass should be caught and which shouldn't ? Or there is more to it ? 回答1: In general, Error is something seriously wrong (often within the platform itself ) which you could not conceivably handle. The only times I have ever cared about catching Error is in order to log it , following which I then re-throw.

NoClassDefFoundError at Runtime with Gradle

 ̄綄美尐妖づ 提交于 2019-11-27 22:59:34
I'm using gradle as the JavaFX plugin. Everything works perfectly even after building and runnig the excecutable at distribution/ , except with one class: CloseableHttpClient For several purposes I create the following object like this: CloseableHttpClient client = HttpClients.createDefault(); Running the program in the IDE is no problem, everything works fine. But if I build and try to run the .exe-File I get the following Throwable -StackTrace: java.lang.NoClassDefFoundError: Could not initialize class org.apache.http.conn.ssl.SSLConnectionSocketFactory at org.apache.http.impl.client