Skip to content

Instantly share code, notes, and snippets.

@sax1johno
Created January 27, 2016 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sax1johno/9f400a178f35ac24cbc1 to your computer and use it in GitHub Desktop.
Save sax1johno/9f400a178f35ac24cbc1 to your computer and use it in GitHub Desktop.
public class HelloWorld{
public static void main(String []args){
System.out.println("Hello World");
Float x = 5;
try {
Float.parseInt(x);
} catch (ParseException e) {
// Required to catch this because of throws statement in method declaraction
System.out.println("Parse exception");
} catch (InvalidFormatException e) {
// Required to catch this because of throws statement in method declaraction
System.out.println("Invalid format exception");
} catch (SomeOtherException e) {
// Not required to catch this but you probably should.
System.out.println("This is another exception here");
} catch (Exception e) {
System.out.println("Some other exception occurred");
// Don't do this if you can help it - it swallows errors and makes code more buggy.
}
}
}
public static Integer parseInt throws InvalidFormatException, ParseException {
throw SomeOtherException("This can be thrown inside the method at any time.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment