Home | History | Annotate | Download | only in util
      1 //  2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html#License
      3 /*
      4  *******************************************************************************
      5  * Copyright (C) 2009-2012, International Business Machines Corporation and    *
      6  * others. All Rights Reserved.                                                *
      7  *******************************************************************************
      8  */
      9 package com.ibm.icu.util;
     10 
     11 /**
     12  * Thrown by methods in {@link ULocale} and {@link ULocale.Builder} to
     13  * indicate that an argument is not a well-formed BCP 47 tag.
     14  *
     15  * @see ULocale
     16  * @stable ICU 4.2
     17  */
     18 public class IllformedLocaleException extends RuntimeException {
     19 
     20     private static final long serialVersionUID = 1L;
     21 
     22     private int _errIdx = -1;
     23 
     24     /**
     25      * Constructs a new <code>IllformedLocaleException</code> with no
     26      * detail message and -1 as the error index.
     27      * @stable ICU 4.6
     28      */
     29     public IllformedLocaleException() {
     30         super();
     31     }
     32 
     33     /**
     34      * Constructs a new <code>IllformedLocaleException</code> with the
     35      * given message and -1 as the error index.
     36      *
     37      * @param message the message
     38      * @stable ICU 4.2
     39      */
     40     public IllformedLocaleException(String message) {
     41         super(message);
     42     }
     43 
     44     /**
     45      * Constructs a new <code>IllformedLocaleException</code> with the
     46      * given message and the error index.  The error index is the approximate
     47      * offset from the start of the ill-formed value to the point where the
     48      * parse first detected an error.  A negative error index value indicates
     49      * either the error index is not applicable or unknown.
     50      *
     51      * @param message the message
     52      * @param errorIndex the index
     53      * @stable ICU 4.2
     54      */
     55     public IllformedLocaleException(String message, int errorIndex) {
     56         super(message + ((errorIndex < 0) ? "" : " [at index " + errorIndex + "]"));
     57         _errIdx = errorIndex;
     58     }
     59 
     60     /**
     61      * Returns the index where the error was found. A negative value indicates
     62      * either the error index is not applicable or unknown.
     63      *
     64      * @return the error index
     65      * @stable ICU 4.2
     66      */
     67     public int getErrorIndex() {
     68         return _errIdx;
     69     }
     70 }
     71