1

Exceptions are extensions of throwables and throwables are defined as implementing serializers in the java packages so can we create throwables in and use try catch and reduce the severity of throwable as exceptions are more threatening. will this allow my code to run smoothly when the throwable is not handled but some communication shall be created between try block code and catch or finally block code.

sorry i do not have any code to share! it's a theoritical doubt as i'm still a beginner learning java.

Trriger
  • 48
  • 10
  • 1
    I don’t know what you mean by “reduce the severity of throwable”. When a throwable (typically an Exception) is thrown, execution jumps immediately to the applicable `catch` or `finally`; there is no changing that to make it “less severe”. – racraman Apr 09 '23 at 05:38
  • but if there were no catch or finally an exception is as severe as an error, does that change if its a throwable instead, and if not how is a throwable different than an exception. thanks for the comment... @racraman – Trriger Apr 09 '23 at 05:42
  • actually that was a part of what stemmed my doubt. let me rephrase my question in this context, so errors and exceptions are broad classification of throwables. But since i'm not aware of any break commands in java to break a block of code and not a loop i could do that using throwables. but while writing this comment i realized... catching throwables makes us lose errors, so shall i make another question or you help me- Can i make a throwable extension with some difference like errors and exception have just in the spirit of knowledge, cuz i have no real use case right now?? thanks a lot – Trriger Apr 09 '23 at 06:26
  • `Error` and `Exception` both extend from ` Throwable `. The difference is basically intent - `Error` is typically thrown by the system, and should be taken as always being fatal - don’t try to catch it or carry on afterwards. At most, all you would do is log it (in some top-level catch) before allowing the application to die. `Exception ` denotes an error in the application - typically recoverable after a `catch`. In short, as a programmer (and especially a beginner) don’t worry about `Error`, you will overwhelmingly be using `Exception`. – racraman Apr 09 '23 at 06:26

0 Answers0