Jump to content

Recommended Posts

Posted

The most prevalent type of exception appears to be java.io.IOException, which also appears to be the most unclear.

When I write using sockets, files, and so on, I keep getting the throws IOException error. I've never had one fired on me, so I'm curious what it is that is intended to fire the exception. The documentation is inadequate in clarifying what is going on:

This indicates that an I/O exception of some kind has happened. This class represents the generic category of exceptions generated by failed or interrupted I/O operations.

What are some scenarios in which an IOException could be raised, and how should it be used?

Posted (edited)

If you are not sure what really happened, but it is on your machine, i.e. you can reproduce the error, use the debugger, in step-by-step mode, until you find the faulty instruction (its name and line number).

If it happens on a third-party machine and you can't reproduce it, you can log things to a temporary file, write something like 1,2,3..100 on each line,

and ask the user to upload this file.

You will find out which instruction caused the exception that you or the user saw.

Then read the instruction manual.

5 hours ago, WalidKhan said:

When I write using sockets, files, and so on, I keep getting the throws IOException error.

Include the source code so we can analyze the code.

5 hours ago, WalidKhan said:

The documentation is inadequate in clarifying what is going on:

You should not read the IOException page, but the page of the instruction that caused the exception.

 

 

5 hours ago, WalidKhan said:

The most prevalent type of exception appears to be java.io.IOException, which also appears to be the most unclear.

When I write using sockets, files, and so on, I keep getting the throws IOException error.

Don't have try {} catch {} for the whole code/function. Have one try-catch per single instruction. Then you will know which line and which instruction caused the exception. Exceptions are thrown to indicate some failure.

 

5 hours ago, WalidKhan said:

What are some scenarios in which an IOException could be raised, and how should it be used?

Inability to access an existing file to read it.

Inability to access an existing file for writing.

Because of insufficient privileges (lack of admin status).

 

Inability to access a file for reading because the file does not exist.

Inability to access a non-existent file for writing due to lack of disk space.

Inability to write data due to lack of disk space.

The file cannot be read because some other application has gained exclusive access to it.

 

..this is just the beginning..

 

Edited by Sensei
  • 1 month later...
Posted

Hello this is Gulshan Negi
Well, it may happen because of several reasons. The most common reason is the user does not have sufficient access rights to the file or directory being accessed, or the file or directory does not exist. Try it and check it again.
Thanks

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.