Hi guys,
So I'm looking at another developers project for learning purposes and I'm just moving through the code so I can get an understanding of what's happening and how to write my own version of it. And the first thing I'm looking at is the 'try ..catch' statement. From what I can tell the purpose of try catch is to try a block of code and if an exception occurs then catch it, In this example I'm not sure how catching is actually working.
try {
Thread.sleep(1);
} catch (InterruptedException e) {
}
I've also seen some basic examples where 0 is divided by a value and it's suppose to throw an Exception, the person then draws a line to say hey you can't divide like that. But in this case what will happen ?
I think more importantly, if an error occurs, does the program crash, and whether or not it crashes will I see a message in Eclipse console telling me what caused the error ?
And then, from what I've read some peoples approach is to determine what exceptions/errors may occur and then change their code to prevent that from happening.
These questions will help me understand whether or not I can take the following approach, code, run the program, attempt all possible interactions, when an error occurs see what it says in the console or rather see what interaction I did that caused it then modify the code to prevent that from happening, instead of catching exceptions.
Update:
I looked up exceptions a bit, I see that InterruptedException is a specific exception that throws when a sleeping thread is interrupted using the interrupt(); method. And that I don't see interrupt being used in the project then the exception is actually not required.
↧