2 * Copyright (C) 2009 The Libphonenumber Authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.i18n.phonenumbers;
20 * Generic exception class for errors encountered when parsing phone numbers.
22 @SuppressWarnings("serial")
23 public class NumberParseException extends Exception {
25 public enum ErrorType {
27 // This generally indicates the string passed in had less than 3 digits in it. More
28 // specifically, the number failed to match the regular expression VALID_PHONE_NUMBER in
29 // PhoneNumberUtil.java.
31 // This indicates the string started with an international dialing prefix, but after this was
32 // stripped from the number, had less digits than any valid phone number (including country
35 // This indicates the string, after any country code has been stripped, had less digits than any
36 // valid phone number could have.
38 // This indicates the string had more digits than any valid phone number could have.
42 private ErrorType errorType;
43 private String message;
45 public NumberParseException(ErrorType errorType, String message) {
47 this.message = message;
48 this.errorType = errorType;
52 * Returns the error type of the exception that has been thrown.
54 public ErrorType getErrorType() {
59 public String toString() {
60 return "Error type: " + errorType + ". " + message;