www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - FileException vs. Exception

reply jicman <jicman_member pathlink.com> writes:
So, I have this function,

|bit FileIsBusy(char[] fn)
|{
|  File f = new File();
|  try
|  {
|    f.open(fn);
|  }
|  catch (Exception e)
|  {
|    return(true);
|  }
|  f.close();
|  return false;
|}

this work, however, if I change "Exception" for "FileException", it does not
work.  if you go to,

http://www.digitalmars.com/d/phobos.html#file

you'll see that it's suppose to be a FileException.  Is this correct?  I don't
understand.

thanks,

josé
Aug 18 2005
next sibling parent reply Burton Radons <burton-radons smocky.com> writes:
jicman wrote:
 So, I have this function,
 
 |bit FileIsBusy(char[] fn)
 |{
 |  File f = new File();
 |  try
 |  {
 |    f.open(fn);
 |  }
 |  catch (Exception e)
 |  {
 |    return(true);
 |  }
 |  f.close();
 |  return false;
 |}
 
 this work, however, if I change "Exception" for "FileException", it does not
 work.  if you go to,
 
 http://www.digitalmars.com/d/phobos.html#file
 
 you'll see that it's suppose to be a FileException.  Is this correct?  I don't
 understand.
That link you gave is for std.file - you're using std.stream. std.stream.File throws std.stream.OpenException when it can't open/create a file. One quick way to figure out what's going on is to do this: catch (Object o) { printf("threw %.*s\n", o.classinfo.name); }
Aug 18 2005
parent reply starkweatherr mchsi.com writes:
Where can I find the current definition of the FileException class, or whatever
it is now?
Mar 20 2006
parent "Regan Heath" <regan netwin.co.nz> writes:
On Tue, 21 Mar 2006 00:07:21 +0000 (UTC), <starkweatherr mchsi.com> wrote:
 Where can I find the current definition of the FileException class, or  
 whatever it is now?
I tend to use the find in files function in TextPad to scan "dmd\src\phobos\" and all subdirectories for "*.d" containing the text I am after, in this case "FileException", results include: std\file.d(59): class FileException : Exception meaning dmd\src\phobos\std\file.d is the file you're after. Regan
Mar 20 2006
prev sibling parent "Ben Hinkle" <bhinkle mathworks.com> writes:
"jicman" <jicman_member pathlink.com> wrote in message 
news:de2akv$2tk2$1 digitaldaemon.com...
 So, I have this function,

 |bit FileIsBusy(char[] fn)
 |{
 |  File f = new File();
 |  try
 |  {
 |    f.open(fn);
 |  }
 |  catch (Exception e)
 |  {
 |    return(true);
 |  }
 |  f.close();
 |  return false;
 |}

 this work, however, if I change "Exception" for "FileException", it does 
 not
 work.  if you go to,

 http://www.digitalmars.com/d/phobos.html#file

 you'll see that it's suppose to be a FileException.  Is this correct?  I 
 don't
 understand.

 thanks,

 josé
FileException is in std.file. The exception thrown by std.stream.File.open is an OpenException, which subclasses StreamFileException (which subclasses StreamException not FileException). I will document the exceptions thrown by the stream classes and send the doc to Walter.
Aug 18 2005