Resource Guide - Try, catch and finally

Discussion in 'Spigot Plugin Development' started by alexhackers, Jun 5, 2017.

  1. You can handle the errors using try and catch, if you use it it will not stop your Java application and will continue, regardless of whether or not it gives an error.

    Whenever you have a try you will have a catch


    Exemple:

    String analisar = "Name";
    try{
    Integer.parseInt(analisar);
    System.out.println("String is a number");

    }catch(NumberFormatException e){
    System.out.println("String not is a number");

    }

    finally:

    It will always be the last one to run, usually used to report a log or something related.

    Exemple:

    String analisar = "1";
    try{
    Integer.parseInt(analisar);
    System.out.println("String is a number");
    }catch(NumberFormatException e){
    System.out.println("String not is a number");
    }finally {
    System.out.println("Finally");
    }

    More in : Java - Try, Catch e Finally
     
    • Like Like x 2
    • Agree Agree x 1
    • Funny Funny x 1
  2. no offense, but this is a really useless guide.
     
    • Agree Agree x 11
    • Funny Funny x 1
  3. You spelled Catch wrong in the title
     
    • Agree Agree x 1
    • Winner Winner x 1
  4. There are people who do not know
     
    • Agree Agree x 2
  5. Pretty useless thread, sorry
     
    • Agree Agree x 3
  6. Thanks, i fix the title
    It's simple
     
    • Agree Agree x 4
  7. Choco

    Moderator

    Don't forget about good ol' Finally
     
    • Informative Informative x 2
    • Winner Winner x 1
  8. Ahh yes, poor finally. Mostly forgotten.
     
    • Friendly Friendly x 1
  9. Put your code into code tags..
    Code (Text):
    String analisar = "Name";
    try{
    Integer.parseInt(analisar);
    System.out.println("String is a number");

    }catch(NumberFormatException e){
    System.out.println("String not is a number");

    }
    Code (Text):
    String analisar = "1";
    try{
    Integer.parseInt(analisar);
    System.out.println("String is a number");
    }catch(NumberFormatException e){
    System.out.println("String not is a number");
    }finally {
    System.out.println("Finally");
    }
     
  10. Thanks, I'm a newbie in spigot forum
     
  11. If someone comes on here and doesn't know this yet I advise them to leave again.
     
    • Agree Agree x 4
  12. This thread is just so useless, this is a fundamental part of Java that all should already know..
     
    • Agree Agree x 1
  13. The people who don't know this probably wouldn't be here in the first place. But sometimes there are some people who come here with absolutely no knowledge with Java whatsoever.
     
  14. I believe that people should know how to do this simple Java concept. If they do not, they should read some simple tutorials on Java before trying to be a Bukkit/Spigot developer.
     
  15. Playing a dumb kid:
    When should is use try and catch
    What does the catch part do
    Why should is use finally and not just put some code after the try catch
    If i have a catch, do i always need a try?
    infinity more....

    Now being me:
    NEVER CATCH OR HANDLE ERRORS.... an error is not an exception. Read the java docs
    Finally is most used for resource handling to close open streamd and shit
    Not catching an error doesn't mean it will stop the program... It means that other apis dont have to worry about it. Only if no api did anything with it, the program stops running
    Don't give google the pleasure to give this website a bad reputation for useless stupid not tutorial posts

    Finally: (See what i have done :))
    You give a description, not an explantion
    You are (a little) wrong with more then 50%
    You are just using random things people may not know about (NumberFormatException)
    I dont want to be rude, but i have to be: learn java, learn bukkit, learn creating tutorials and after that just leave.

    For people saying thay a person should not be at this place if he doesnt know what a NumberFormatException is. You expect them to know that if they dont know what try catch is?
     
    #16 Remceau, Jun 6, 2017
    Last edited: Jun 6, 2017
  16. is this about the mistake i made: pit instead of put? if so i am sorry, i am at my phone at the moment
     
    • Funny Funny x 1
  17. fur I knew you where from germany...
     
  18. Best Tutorial Ever...
     
    • Agree Agree x 1
  19. Dude, this is just a joke :p.