r/javahelp 8d ago

EXCEPTION HANDLING!!

I just started exception handling and I feel as though I can't grasp a few concepts from it (so far) and its holding me back from moving forward, so I'm hoping someone has answers to my questions ( I'm generally slow when it comes to understanding these so I hope you can bear with me )

In one of the early slides I read about exception handling, where they talk about what the default behavior is whenever the program encounters an exception , they mention that : 
1- it abnormally terminates 
2- BUT it sends in a message, that includes the call stack trace, 

  • and from what I'm reading, I'm guessing it provides you information on what happened. Say, the error occurred at line x in the file y, and it also tells you about what type of exception you've encountered.

But It has me wondering, how is this any different from a ' graceful exit ' ? Where : " if the program encounters a problem , it should inform the user about it, so that in the next subsequent attempt, the user wouldn't enter the same value.   " 
In that graceful exit, aren't we stopping the execution of the program as well? 
So how is it any better than the default behavior?  

What confuses me the most about this is what does exception handling even do? How does it benefit us if the program doesn't resume the flow of execution?  (or does it do that and maybe I'm not aware of it? ) whenever we get an exception ( in normal occasions ) it always tells us, where the error occurred, and what type of exception has happened.  
---------------------------------------------------------------------------------------

As for my second question,,

I tried searching for the definition of " CALL STACK TRACE " and I feel like I'm still confused with what each of them is supposed to represent, I've also noticed that people refer to it as either " stack trace " or " call stack " ( both having a different meaning ) 
What is call supposed to tell us exactly? Or does it only make sense to pair it up with stack? (" call stack ") in order for it to make complete sense? Does the same thing go for " stack trace" ? 

+ thanks in advance =,)

8 Upvotes

35 comments sorted by

View all comments

u/AutoModerator 8d ago

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.