With exception handling.

Lab Notes
Clarifying exception handling
by Matt Brenner
Listing 2. With exception handling.


1  public static final double
2  todouble (String text)
3  {
4       doubleval;
5
6
7       try {
8           val = Double.valueOf (text).doubleValue();
9       }
10     catch (NumberFormatException e) {
11         val = Double.NaN;
12     }
13
14     return (val);
15 }