Results 1 to 4 of 4

Thread: [RESOLVED] [2008] Exception Handling

  1. #1

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Resolved [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?

  2. #2
    Lively Member
    Join Date
    Jul 2008
    Posts
    107

    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

  3. #3

    Thread Starter
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Re: [2008] Exception Handling

    Thanks, that seems to be what I remember.
    What about automatic detection/fixes in the IDE?

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: [2008] Exception Handling

    I've never been warned, so at least up to 2005, there is no automatic detection.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width