[RESOLVED] [2008] Exception Handling
I have been forced into Java for my job for the last year or so and have been using Intellij IDEA as an IDE.
Coming back to VS I was a bit confused about the Exception Handling in VB.NET.
First question:
Does VB.NET have the ability to add Exceptions to methods?
e.g. in Java you could do this
Code:
public void readFile(String fileName) throws IOException {
...
...
}
Can you do this in VB.NET?
What should you do if you want to throw the exception up the stack?
Second Question:
In IDEA of I don't add the exception to the method at first, then add some code like this:
Code:
public void ReadFile(String fileName) {
BufferedReader reader = null;
new BufferedReader(new FileReader(fileName));
}
the IDE tells me that an Exception could be thrown by this block and gives me the option to automatically fix it by surrounding it with a Try/Catch or by adding the exception to the method signature.
Does VS have these automatic detection/fixes?
Re: [2008] Exception Handling
agmorgan,
No, .net does not require or permit you to decorate method headers with possible exceptions that might be thrown.
To pass the exception up the call stack you can just not catch the exception in the local method or you can catch the exception and re-throw it or another exception with the Throw keyword.
Kerry Moorman
Re: [2008] Exception Handling
Thanks, that seems to be what I remember.
What about automatic detection/fixes in the IDE?
Re: [2008] Exception Handling
I've never been warned, so at least up to 2005, there is no automatic detection.