-
February 1st, 2011, 10:25 PM
#1
Exception Handling Problems
Whenever I put something within my try-catch blocks, I get this error "cannot find symbol" when I have already defined everything clearly for each try-catch blocks. None of the try catch blocks work, dunno why.
-
February 2nd, 2011, 01:56 AM
#2
Re: Exception Handling Problems
Unless you show us the code and the full error message it's hard to say what is wrong other than maybe you haven't declared a variable/method you are using or you haven't added an import statement you need.
-
February 2nd, 2011, 02:04 AM
#3
Re: Exception Handling Problems
If this is a duplicate of your other thread then please close one of them or it's going to get really confusing.
And where's the full error message?
-
February 2nd, 2011, 02:20 AM
#4
Re: Exception Handling Problems
client1 is declared inside the try block and so is local to that block. You need to declare client1 outside the try block.
BTW I should point out you should be closing the socket in a finally block else if any of your code throws an exception the socket won't be closed.
And learn how to use code tags - read the blue text below this line to see how it is done.
-
February 2nd, 2011, 02:26 AM
#5
Re: Exception Handling Problems
I haven't looked - it's hard to read code that hasn't been formatted (hence we keep asking you to use code tags). And I don't have the time at the moment so you'll just have to run it and see if it works.
Good Luck.
-
February 2nd, 2011, 02:29 AM
#6
Re: Exception Handling Problems
Oh nvm tks, will get back 2 u if I face any more probs, tks 4 ur tym.
-
February 2nd, 2011, 04:34 AM
#7
Re: Exception Handling Problems
My time-stampping doesn't give any output, dunno why
You are creating the TimeStamp objects but then not doing anything with them. What are you trying to achieve?
-
February 2nd, 2011, 05:37 AM
#8
Re: Exception Handling Problems
Oh ya, I din realise earlier, was so caught up in fixing my exceptions. Basically, I need time-stamps to check that curr time doesn differ from the time-stamp time by more than 1 min & if it does to retransmit data. I m not sure how to reestablish connection to retransmit data, do I create a new socket for connection re-establishment? Since m implementing a simplified Kerberos protocol, m not sure how to handle the creation of challenges either. Coding on Kerberos seems to be very little on the net, in fact I can hardly find exaamples. If u have knowledge on Kerberos pls share, tks.
-
February 2nd, 2011, 11:49 AM
#9
Re: Exception Handling Problems
Just a small point on exception handling Susan, that will make coding simpler and the finished code clearer...
The try...catch structure is designed to allow you to write the bulk of your code without worrying about the errors until the end of the method. So you should open a single 'try' block, write all the method code, then catch all the errors at the end, e.g.:
Code:
public void aMethod {
// declare variables that may need tidying up after errors
...
try {
// initialise variables
...
// put main body of method code here, ignoring exceptions
...
...
}
// now the main work has been done, handle any problems that may have occurred
catch (ExceptionA a) {
... // handle a
}
catch (ExceptionB b) {
... // handle b
}
finally {
... // tidy up variables, close handles, etc.
}
} // end of method
Sometimes you may want to handle an exception and carry on, in which case you could just nest a single try..catch in the body of the code, but the preferred way is to put that piece of code into it's own method so its try..catch is hidden from the main code. This keeps the code body clear of messy exception handling, and ensures all methods follow the same 'single try, multiple catch' formula.
It's only a guideline, but it is Best Practice
Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves...
Alan Kay
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
February 2nd, 2011, 11:08 PM
#10
Re: Exception Handling Problems
I can do that but m trying to fix my socket connection now again, it says my client hasn't been intialized.
This is my errorneous code
Client:
Code:
Socket client1; //Defined outside
BufferedReader userInput; //Defined outside
DataOutputStream ServerOut; //Defined outside
BufferedReader ServerInfo; //Defined outside
try {
client1 = new Socket("127.0.0.1",9001);
} catch (UnknownHostException e) {
System.err.println(e);
System.exit(1);
} catch (IOException e) {
System.err.println(e);
System.exit(1);
}
Server:
Code:
Socket socket1; // Defined outside
BufferedReader ClientInfo; //Defined outside
ClientInfo =
new BufferedReader(new InputStreamReader(socket1.getInputStream()));
-
February 3rd, 2011, 10:17 AM
#11
Re: Exception Handling Problems
If you get an error, please post the full error message and stack trace, if present.
Incidentally, socket1 on the server has been declared but hasn't been initialised.
Optimism is an occupational hazard of programming; feedback is the treatment...
Kent Beck
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|