Exceptions Quiz - Java Object Oriented Design

Java examples for Object Oriented Design:Exception

Introduction

Parse String value to float value.

Handle an exception inside a catch block.

Demo Code

public class Main {
  public static void main(String[] arguments) {
    try {/*from   w  w  w .  j a v  a2  s  .c  o  m*/
      float in = Float.parseFloat("aa");
      // rest of method
    } catch (NumberFormatException nfe) {
      System.out.println(" not a valid number.");
    }
  }
}

Result


Related Tutorials