Results 1 to 5 of 5
  1. #1
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    241
    Rep Power
    3

    Default How do I ignore an alert?

    I am getting an alert from NetBeans because I am lacking a return statement at the very end of a method, however it is impossible for the program to ever run the end of that method as it will be returned by an if statement within it. The method itself will only ever run if one of the if statements (which will return the method) will be executed.


    Therefore, even though NetBeans thinks there is an issue, there isn't.
    How can I ignore this alert (e.g. like you can select ignore on a bad spelling in Microsoft Word).

  2. #2
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    241
    Rep Power
    3

    Default Re: How do I ignore an alert?

    I have actually sorted it now just by creating a "dummy" return statement to shut NetBeans up. However, it would be nice to know for future.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,122
    Rep Power
    20

    Default Re: How do I ignore an alert?

    If the compiler thinks you're missing a return then there is no way to compile your code.
    Nothing to do with Netbeans.
    You may feel you "know" it can't get to that line, but that's irrelevant if the compiler doesn't.
    eg
    Java Code:
    boolean someMethod(int someParameter) {
       if (someParameter == 1) {
          return true;
       }
       if (someParameter == 0) {
          return false;
       }
    }
    I may "know" that 'someParameter' is only ever going to be 1 or 0, but the compiler doesn't.
    There is nothing in that code up there to tell it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    241
    Rep Power
    3

    Default Re: How do I ignore an alert?

    pfft, stupid compiler.


    I've got around it by putting a return statement of the correct type anyway where a "dummy" object would have been created.


    Thanks for letting me know.


    Is there a way to ignore the alerts in NetBeans though if you wanted to for some reason (not necessarily a vital alert telling you it will not compile)?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,122
    Rep Power
    20

    Default Re: How do I ignore an alert?

    There are warnings and errors that come from the compiler.
    I expect there's a way of telling Netbeans to not show warnings, but you'd need to search in the help file.

    In the case of your code, if certain values are invalid then I would throw some form of RuntimeException, since it means your code is broken.
    Don't trust someone (even yourself) remembering the restrictions on calling your method.
    Throw the exception so at least the code crashes in a spectacular way and will, therefore, never pass testing.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Test - please ignore
    By Junky in forum New To Java
    Replies: 0
    Last Post: 02-03-2011, 05:03 AM
  2. ignore backspace
    By Kyle227 in forum New To Java
    Replies: 6
    Last Post: 05-16-2010, 10:34 PM
  3. *TEST* --ignore this--
    By angryboy in forum Reviews / Advertising
    Replies: 5
    Last Post: 05-01-2009, 09:15 AM
  4. Ignore Symbol
    By Xystus777 in forum New To Java
    Replies: 2
    Last Post: 01-21-2009, 01:24 AM

Posting Permissions

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