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 com.lokalized.Diagnostics.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 /** The unsupported locale that triggered this exception. */ 037 @NonNull 038 private final Locale locale; 039 040 /** 041 * Constructs a new exception with the unsupported locale. 042 * 043 * @param locale the unsupported locale which triggered this exception, not null 044 */ 045 public UnsupportedLocaleException(@NonNull Locale locale) { 046 super(format("Unsupported locale '%s' was provided", requireNonNull(locale).toLanguageTag())); 047 this.locale = locale; 048 } 049 050 /** 051 * The unsupported locale that triggered this exception. 052 * 053 * @return the unsupported locale, not null 054 */ 055 @NonNull 056 public Locale getLocale() { 057 return locale; 058 } 059}