NotADirectoryException?

I've written a method in a class that is to create a file list of all the files in a given directory. Works fine.
Now I wanted to implement error handling. The user might enter a directory that does not exist or one that is really a file and not a directory.
For the first case, I used
    File f = new File(folder);
    if (!f.exists())
      throw new FileNotFoundException("Ordner "+folder+" existiert nicht.");
    }But what do I do about the second case? I have looked at the different IOExceptions, but there seems to be none that is to be thrown when a File is not a directory.
    if (! f.isDirectory())
      throw new XyzException(folder+" ist kein Verzeichnis.");
    }What should I put in place of Xyz ?
I could of course simply use throw new IOException(folder+" ist kein Verzeichnis."), but that is not very good, I think. A more specific Exception is better, or is it not?
Can anyone help me?
Monika.

How about creating a new exception that extends
IOException.
public class DirectoryNotFoundException extends
IOException {
public DirectoryNotFoundException () {
super();
public DirectoryNotFoundException (String message)
super(message);
}Then change your code to...
throw new DirectoryNotFoundException(folder+" ist kein
Verzeichnis.");Thanks, works just fine :-)
In the JDC newsletter about exceptions, it said it's not good to create one's own exceptions, but I think it's the best solution here.
Monika.

Similar Messages

Maybe you are looking for

  • Bonjour for windows gives this error - You do not have sufficient access...

    I installed Bonjour for windows on a PC running XP. When I run the Bonjour app from windows I can see the printer I wish to connect to. It is shared off of my G3 server. When I try to connect I get the following error, "You do not have sufficient acc

  • I can't open iTunes on my msi windows laptop

    i have an msi cr620 and i cant open itunes for some reason. this was my first pc before changing to this imac, all or most of my library is on this pc and i need it to dj at a party on 25th of this month so any ideas would be welcome. ive thought of

  • This is in response to: My old computer died. How do I add new songs to my iPhone using a "new" library?

    It won't let me reply to you for some reason. 1. Go into Itunes. Go to preferences. Go to advanced. Check 'Keep Itunes media folder organized' and 'Copy folders to itunes media folder when adding libraries'. Press Okay. 2.Hook up Iphone to computer w

  • HELP! opening a pdf file and using page view

    Hi everyone! I'm doing a school project in which I'm trying to develop an app that opens a pdf file from the device memory (ipad or iphone) and lets the user turn pages forward and backward by swiping on the screen. Although I have very basic knowled

  • Progress bar in JSP

    Hello Guyz, I need some idea to put up a progress bar. I want to implement this in pure JSP without using any swing components or Javascript. Can i do it using Just JSP..and servlets in.. Im doing this is in MVC architecture... So please do help me..