473,395 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Error with throwing different exceptions

Nepomuk
3,112 Expert 2GB
I have a encountered a weird problem. I have the following code:
Expand|Select|Wrap|Line Numbers
  1. public void connect() 
  2. throws IOException, IllegalAccessException
  3. {
  4.     try
  5.     {
  6.         ftp.connect(server);
  7.         ftp.login(username, password);
  8.         ftp.setFileType(FTP.BINARY_FILE_TYPE);
  9.         String reply = ftp.getReplyString(); 
  10.         if(reply.indexOf("530") != -1) throw new IllegalAccessException(reply);
  11.     }
  12.     catch(SocketException se)
  13.     {
  14.         throw se;
  15.     }
  16.     catch(IOException ioe)
  17.     {
  18.         throw ioe;
  19.     }
  20. }
and I get the following runtime error:
Expand|Select|Wrap|Line Numbers
  1. Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
  2.     Exception IllegalAccessException is not compatible with throws clause in DownloadServiceClient.connect()
  3. ...
If however I add arguments to the methods call, e.g.
Expand|Select|Wrap|Line Numbers
  1. public void connect(int a) 
  2. throws IOException, IllegalAccessException
  3. ...
it works perfectly.

I'm using compilance level 1.3, as this project should be runnable on old systems. Oh, and that ftp object is a org.apache.commons.net.ftp.FTPClient (not that that would make any difference at this point, as far as I can tell).

By the way, it doesn't matter, if it's an IllegalAccessException, a FileNotFoundException or any other Exception that I have tested. It's always the same error.

Can anyone help me in my confusion?

Greetings,
Nepomuk
Aug 12 '08 #1
8 2223
JosAH
11,448 Expert 8TB
What exactly is the throws clause of the DownloadServiceClient.connect() method?

kind regards,

Jos
Aug 12 '08 #2
Nepomuk
3,112 Expert 2GB
What exactly is the throws clause of the DownloadServiceClient.connect() method?

kind regards,

Jos
OK, I should have specified:
Expand|Select|Wrap|Line Numbers
  1. public class DownloadServiceClient {
  2. ...
  3. public void connect() 
  4. throws IOException, IllegalAccessException
  5. {
  6.     try
  7.     {
  8.         ftp.connect(server);
  9.         ftp.login(username, password);
  10.         ftp.setFileType(FTP.BINARY_FILE_TYPE);
  11.         String reply = ftp.getReplyString(); 
  12.         if(reply.indexOf("530") != -1) throw new IllegalAccessException(reply);
  13.     }
  14.     catch(SocketException se)
  15.     {
  16.         throw se;
  17.     }
  18.     catch(IOException ioe)
  19.     {
  20.         throw ioe;
  21.     }
  22. }
  23. ...
  24. }
So the thows clause is: throws IOException, IllegalAccessException, right?

Greetings,
Nepomuk
Aug 12 '08 #3
Nepomuk
3,112 Expert 2GB
Arg, found the error. Sorry, silly mistake. It isn't the class DownloadServiceClient but DownloadServiceFTPClient that method came from, DownloadServiceClient being an interface... Anyway, problem solved. Thanks!

Greetings,
Nepomuk
Aug 12 '08 #4
JosAH
11,448 Expert 8TB
So the thows clause is: throws IOException, IllegalAccessException, right?
Yep, as far as I can see; what I don't understand is, you're talking about a Runtime
error while that error diagnostic message is talking about an unresolved compilation
problem. Your compiler must've whined there as well when you were compiling
your class.

kind regards,

Jos
Aug 12 '08 #5
JosAH
11,448 Expert 8TB
Anyway, problem solved. Thanks!
What was it then?

kind regards,

Jos
Aug 12 '08 #6
Nepomuk
3,112 Expert 2GB
What was it then?

kind regards,

Jos
I have an interface DownloadServiceClient with
Expand|Select|Wrap|Line Numbers
  1. /**
  2.  * Connect to the given Server
  3.  */
  4. public void connect() throws IOException;
and a class DownloadServiceFTPClient with two connect methods - one with and one without arguments. I had not added the IllegalAccessException to the throw cause in my interface, so that wouldn't work. The other connect method wasn't interfaced, so it worked fine.
Oh, the thing about the compiler was a bit weird. I'm using Eclipse with jdk1.4.2 and it did say something like "There are errors in your project. Still continue?" It did compile, without complaining further (it should have, shouldn't it?) and then threw the error at runtime.

Anyway, I'm glad the error is resolved.

Greetings,
Nepomuk
Aug 12 '08 #7
JosAH
11,448 Expert 8TB
I have an interface DownloadServiceClient with
Expand|Select|Wrap|Line Numbers
  1. /**
  2.  * Connect to the given Server
  3.  */
  4. public void connect() throws IOException;
and a class DownloadServiceFTPClient with two connect methods - one with and one without arguments. I had not added the IllegalAccessException to the throw cause in my interface, so that wouldn't work. The other connect method wasn't interfaced, so it worked fine.
Oh, the thing about the compiler was a bit weird. I'm using Eclipse with jdk1.4.2 and it did say something like "There are errors in your project. Still continue?" It did compile, without complaining further (it should have, shouldn't it?) and then threw the error at runtime.
Well, it already complained but you choose to ignore it; never run anything when
Eclipse whines about errors in the project (see those little red marks near the
files in your package browser). Eclipse is ruthless and you get what you deserve ;-)

kind regards,

Jos
Aug 12 '08 #8
Nepomuk
3,112 Expert 2GB
Well, it already complained but you choose to ignore it; never run anything when
Eclipse whines about errors in the project (see those little red marks near the
files in your package browser). Eclipse is ruthless and you get what you deserve ;-)

kind regards,

Jos
Actually, I chose to ignore it so as to find a out, where the error would strike. I did find out. In this case, that knowledge was useless, but it won't always be! :-D

Greetings,
Nepomuk
Aug 12 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Mark Oueis | last post by:
I've been struggling with this question for a while. What is better design? To design functions to return error codes when an error occures, or to have them throw exceptions. If you chose the...
8
by: Shane Groff | last post by:
I know this is a recurring discussion (I've spent the last 3 days reading through threads on the topic), but I feel compelled to start it up again. After reading through the existing threads, I...
9
by: Rennie deGraaf | last post by:
If a C++ I/O operation fails, then how can I determine the cause? For instance, in C, I'd do something like this: FILE* file; file = fopen("foo.txt", "r"); if (file == NULL) { switch(errno)...
11
by: suzy | last post by:
i am trying to write aspx login system and the login process requires a validity check of username and password. i have been told that raising exception is costly, but i want a custom error...
3
by: Steve - DND | last post by:
I was wondering if anyone can point me to some articles or practices they use for dealing with errors in their applications; particularly in an n-tier design. I am trying to find one way to...
40
by: Sek | last post by:
Is it appropriate to throw exception from a constructor? Thats the only way i could think of to denote the failure of constructor, wherein i am invoking couple of other classes to initialise the...
16
by: lawrence k | last post by:
I've made it habit to check all returns in my code, and usually, on most projects, I'll have an error function that reports error messages to some central location. I recently worked on a project...
9
by: Jim | last post by:
Hello, I'm trying to write exception-handling code that is OK in the presence of unicode error messages. I seem to have gotten all mixed up and I'd appreciate any un-mixing that anyone can...
35
by: jeffc226 | last post by:
I'm interested in an idiom for handling errors in functions without using traditional nested ifs, because I think that can be very awkward and difficult to maintain, when the number of error checks...
16
by: john6630 | last post by:
Coming from the .Net world, I am used to the try...catch...finally approach to error handling. And PHP 5 now supports this approach. But I am not clear what happens to unhandled errors/exceptioins?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.