简体   繁体   中英

Java IO Exception Catching

I need my application to bring up an error in writing to the location /dev/full . Is there anyway I can do this with Java exception handling? I am already throwing and catching IOerrors, so I don't know what the problem is...?

I am reading data from standard in, and compressing it and writing it to standard out.

Writing to /dev/full isn't raising an exception...any ideas on how to raise an exception for this?

There is a Parent Class for all Exceptions that is Exception . If you are not sure which type of exceptions are thrown from try block, use Exception in your last catch block.

something like this

try{
   ....//code here
}
catch(FileNotFoundException fnfe){
    log(fnfe);
}
catch(IOException ioe){
    log(ioe);
}
catch(Exception e){
    log(e);
}
finally{
  ....//code here
}

You could write a code for writing all the details of the error and any specific comments you wish to make regarding the class or object so that you can trace the error better inside the catch block.

try
{
//Your code
}
catch(SomeException e)
{
//Create a file, write data to it and close it.
}

I use this technique to save user data in case a file cannot be opened for modifications. Helps because i am sure that the data will be stored at either of the 2 places.

Also, this doesn't affect my further executing of the program as the data is loaded in an object of File .
There could be better methods to the above. But this is what my professor showed me. Could be of use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM