001/* 002 * Copyright 2017-2022 Product Mog LLC, 2022-2026 Revetware 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 org.jspecify.annotations.NonNull; 020 021import javax.annotation.concurrent.NotThreadSafe; 022import java.util.Locale; 023 024import static java.lang.String.format; 025import static java.util.Objects.requireNonNull; 026 027/** 028 * Exception thrown when an operation was performed on a locale that is not recognized by the system. 029 * <p> 030 * This class is intended for use by a single thread. 031 * 032 * @author <a href="https://revetkn.com">Mark Allen</a> 033 */ 034@NotThreadSafe 035public class UnsupportedLocaleException extends RuntimeException { 036 @NonNull 037 private final Locale locale; 038 039 /** 040 * Constructs a new exception with the unsupported locale. 041 * 042 * @param locale the unsupported locale which triggered this exception, not null 043 */ 044 public UnsupportedLocaleException(@NonNull Locale locale) { 045 super(format("Unsupported locale '%s' was provided", requireNonNull(locale).toLanguageTag())); 046 this.locale = locale; 047 } 048 049 /** 050 * The unsupported locale that triggered this exception. 051 * 052 * @return the unsupported locale, not null 053 */ 054 @NonNull 055 public Locale getLocale() { 056 return locale; 057 } 058}