1 /* 2 * Copyright (C) 2009 The Libphonenumber Authors 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 package com.android.i18n.phonenumbers; 18 19 /** 20 * Generic exception class for errors encountered when parsing phone numbers. 21 */ 22 @SuppressWarnings("serial") 23 public class NumberParseException extends Exception { 24 25 public enum ErrorType { 26 INVALID_COUNTRY_CODE, 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. 30 NOT_A_NUMBER, 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 33 // code) could have. 34 TOO_SHORT_AFTER_IDD, 35 // This indicates the string, after any country code has been stripped, had less digits than any 36 // valid phone number could have. 37 TOO_SHORT_NSN, 38 // This indicates the string had more digits than any valid phone number could have. 39 TOO_LONG, 40 } 41 42 private ErrorType errorType; 43 private String message; 44 45 public NumberParseException(ErrorType errorType, String message) { 46 super(message); 47 this.message = message; 48 this.errorType = errorType; 49 } 50 51 /** 52 * Returns the error type of the exception that has been thrown. 53 */ 54 public ErrorType getErrorType() { 55 return errorType; 56 } 57 58 @Override 59 public String toString() { 60 return "Error type: " + errorType + ". " + message; 61 } 62 } 63