001/* 002 * Copyright 2017 Product Mog LLC. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.lokalized; 018 019import javax.annotation.Nonnull; 020import javax.annotation.concurrent.NotThreadSafe; 021import java.util.Locale; 022 023import static java.lang.String.format; 024import static java.util.Objects.requireNonNull; 025 026/** 027 * Exception thrown when an operation was performed on a locale that is not recognized by the system. 028 * <p> 029 * This class is intended for use by a single thread. 030 * 031 * @author <a href="https://revetkn.com">Mark Allen</a> 032 */ 033@NotThreadSafe 034public class UnsupportedLocaleException extends RuntimeException { 035 @Nonnull 036 private final Locale locale; 037 038 /** 039 * Constructs a new exception with the unsupported locale. 040 * 041 * @param locale the unsupported locale which triggered this exception, not null 042 */ 043 public UnsupportedLocaleException(@Nonnull Locale locale) { 044 super(format("Unsupported locale '%s' was provided", requireNonNull(locale).toLanguageTag())); 045 this.locale = locale; 046 } 047 048 /** 049 * The unsupported locale that triggered this exception. 050 * 051 * @return the unsupported locale, not null 052 */ 053 @Nonnull 054 public Locale getLocale() { 055 return locale; 056 } 057}