Questions tagged [throwable]

The `Throwable` class is the superclass of all errors and exceptions in the Java programming language. Only objects that are instances of this class (or one of its subclasses) are thrown by the Java VM or could be thrown by the Java `throw` statement.

The Throwable class is the superclass of all errors and exceptions in the Java programming language. Only objects that are instances of this class (or one of its subclasses) are thrown by the Java VM or could be thrown by the Java throw statement. Similarly, only this class or one of its subclasses can be the argument type in a catch clause. For the purposes of compile-time checking of exceptions, Throwable and any subclass of Throwable that is not also a subclass of either RuntimeException or Error are regarded as checked exceptions.

For the further details and reference the documentation for Class Throwable.

165 questions
3
votes
3 answers

Question about Java.lang.Error

There are lot of posts on java.lang.Error saying it should not be caught. My question is if it should not be caugth the what is the use of it. Since it is Throwable so we can catch it in try catch. I read some posts like only in some situation it…
Amit
  • 31
  • 1
3
votes
2 answers

Different behaviour while catching Throwable and StackOverflowError

I have the below two sets of code First Set of code is as below: public static void main(String[] args){ try { main(null); } catch (Throwable e) { } System.out.println("Value of args[0] is : "args[0]); } Output is : Value…
Jagadeesh
  • 862
  • 7
  • 23
3
votes
2 answers

good documentation about "avoid catching throwable", in context of weblogic server

I am currently refactoring an existing codebase (EJBs) to rip out all blocks where a Throwable is caught inside of the EJB. try { ... do some business logic } catch(Throwable t){ ... log and swallow ... :-( } I want/need to convince the…
Marcel
  • 710
  • 8
  • 23
3
votes
2 answers

How to set my own message in my custom exception in Java that can be retrieved my getMessage() BUT WITHOUT using the constructor, is there any way?

I'm just learning about exception handling in Java. What I would like to know is rather than trying something like say: throw new Exception("My Message"); and String message=ex.getMessage(); System.out.println(message); Take a look at the code…
Sainath S.R
  • 3,074
  • 9
  • 41
  • 72
3
votes
2 answers

Should a control library that runs user-supplied code intercept Exceptions or Throwables?

I've seen here many general questions about the difference between Exception and Throwable. I know the difference, and I have a more specific question. I'm writing a library that binds and runs together several user-supplied pieces of code. If one…
Petr
  • 62,528
  • 13
  • 153
  • 317
2
votes
4 answers

About java Throwable

when I develop android application,I want to make a CrashReport class and then use it send report to my server. I make a class called CrashHandler which implement UncaughtExceptionHandler,and make a example to cause a NullPoint error in Activity in…
daimajia
  • 967
  • 12
  • 15
2
votes
1 answer

Why do the following methods of the Throwable class need to be synchronized?

private StackTraceElement[] stackTrace = UNASSIGNED_STACK; private transient Object backtrace; private synchronized StackTraceElement[] getOurStackTrace() { // Initialize stack trace field with information from // backtrace if this is the…
kuyyi
  • 29
  • 3
2
votes
2 answers

Efficient way to get caller method in Java 8?

This is what I'd like to achieve: if there is a method a() which calls method b(), I'd like to know who called method b(). public void a(){ b();//but it is not necessarily in the same class } public void b(){ String method =…
Nfff3
  • 321
  • 8
  • 24
2
votes
3 answers

Better way to write the checkOrElseThrow generic function

I have two function calls for Employee and Address DAO class where I check if the employee name or address is already in used For making it generic to check and throw exception I have created the following generic function checkOrElseThrow in…
Alex Man
  • 4,746
  • 17
  • 93
  • 178
2
votes
1 answer

Error conversion in Scala in a pure and safe way

I'm using cats-effect to suspend side effects and came across difficulties when implementing pure functions avoiding error-prone Throwables. The problem is that cats.effect.Sync[F[_]] extends Bracket[F, Throwable]. sealed trait Err final case…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
2
votes
7 answers

No exception of type Exception can be thrown, an exception type must be a subclass of Throwable

I was seaching this problem in other questions but still didn't figure out what does exactly mean Throwable. Read a few articles about it (its superclas bla bla bla) but still don't know how to implement it. Forgot to mention i am new to java. Any…
VL4DiMiRG
  • 67
  • 1
  • 2
  • 8
2
votes
1 answer

RxJava How to throw error from Observable.fromCallable(()

If I use: class 1: Observable.fromCallable(() -> awsS3.beginUpload(data.bmpPath)); class2: public String beginUpload(String filePath) { //what if I want to throw error here? } how can I throw an Observable error in the beginUpload() method?
Mike6679
  • 5,547
  • 19
  • 63
  • 108
2
votes
2 answers

java.lang.Throwable: setStateLocked

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 =…
HeatKai C
  • 65
  • 1
  • 9
2
votes
1 answer

Uses for protected Throwable Constructor

Since Java 7, the java.lang.Throwable class has a new protected constructor: protected Throwable(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) It seems to give fine-grained control about…
Clashsoft
  • 11,553
  • 5
  • 40
  • 79
2
votes
1 answer

AssertionError and assert

I'm preparing for OCP 7, and I encountered this essay on one of that certificate books. To discourage you from trying to substitute an assertion for an exception, the AssertionError doesn’t provide access to the object that generated it. All…
Aladdin
  • 1,207
  • 2
  • 16
  • 26