Try buffer thingyY?
Hi guys, iv'e been reading some of the posts and i see this a lot.
try{
//bunch of code
}
Is this like a do while loop, or it always executes?
Any explanation would help please.
MS
Hi guys, iv'e been reading some of the posts and i see this a lot.
try{
//bunch of code
}
Is this like a do while loop, or it always executes?
Any explanation would help please.
MS
Hey Jverd thanks for the link but i still got a couple of questions.
1. Should i use the try block from the beggining of the code to the end because i wouldn't know when there would be an error, or is there a specific place to use try?
for example if this is my code should i always do this?
public static main void--
{
try{
//my whole program
}
If not then during which part of my code should i use it?
P.S. sorry to be pestering you but they haven't taught us this yet in school im jsut curious why you guys write it.
Thanks
MS
Sure you can wrap your entire program in a try statement but I think that is lazy and loathesome. You should aim to only wrap the section of code that will cause an exception. How do you know when an exception occurs? You could just compile and the error message will tell you that you haven't handled an exception or you could read about the method you are calling in the API and it will tell you what kind of exception it throws.
try {
callMethodThatThrowsException();
} catch(NastyException e) {
// handle exception
}
public void callMethodThatThrowsException() throws NastyException {
throw new NastyException();
}