Possible Duplicate:
C# explicitly defining what exceptions are thrown
I have a piece of Java code like this:
public interface ByteSource
{
public void open() throws IOException;
public void close();
public byte readByte() throws IOException;
public void writeBytes(byte[] bytes) throws IOException;
}
I am no Java expert (nor .NET one!) and I want to make a similar interface for .NET but I am not sure what to do about throws ..... I would like to know what does this means in Java language.
Should I care about it? At the moment the best thing (Or only thing I can think of) will be look like:
public interface IByteSource
{
void Open();
void Close();
byte ReadByte();
void WriteBytes(byte[] bytes);
}
Is there an approach in .NET similar to the java code?! Maybe some attributes ?!
I wouldn’t care about it. Checked exceptions were not added to .NET for lots of reasons, but basically because in most cases they are more of a hindrance than a help. You could perhaps use
///to document the things it might be reasonably expected to throw, but leave it up to the call-chain to decide whether they handle that specifically. For example: