coolnickname

Untitled

Dec 2nd, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. try{
  2. int poop = Integer.parseInt("Not a number");
  3.  
  4. //All code happening in the try{} AFTER the parsing of the int will onloy execute if it worked, so if it was a number.
  5.  
  6. }catch(Exception e){
  7. //This code will only execute if there was an exception. As I don't remember the exact Exception name, I just used Exception.
  8. //Which is like a joker as it will detect all exceptions. (It's probs something like InvalidNumberException)
  9.  
  10. //Use this to print the error to the console (which you probs don't want but meh).
  11. e.printStackTrace();
  12. //If you don't use that line the error will still occur but not spam the console.
  13.  
  14. //Now tell the player their numer was invalid:
  15. player.sendMessage("Not a number smartass");
  16. }
Advertisement
Add Comment
Please, Sign In to add comment