Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Program {
- public static void main(String[] args) {
- String invalid = "turnip";
- int result = -100; // A default result.
- try {
- // This throws an exception because the string is invalid.
- result = Integer.parseInt(invalid);
- } catch (NumberFormatException n) {
- // ... Do nothing.
- }
- System.out.println(result); // Prints default result.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement