001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.commons.conversion; 018 019/** 020 * Thrown by {@link Converter#to(Object, Class)} when no conversion path exists between two types. 021 * 022 * <p> 023 * This is an unchecked exception. Callers that are uncertain whether a conversion is possible should 024 * call {@link Converter#canConvert(Class, Class)} first, or catch this exception and handle accordingly. 025 * 026 * <h5 class='section'>Example:</h5> 027 * <p class='bjava'> 028 * <jk>try</jk> { 029 * Integer <jv>x</jv> = BasicConverter.<jsf>INSTANCE</jsf>.to(<js>"hello"</js>, Integer.<jk>class</jk>); 030 * } <jk>catch</jk> (InvalidConversionException <jv>e</jv>) { 031 * <jc>// Handle unsupported conversion</jc> 032 * } 033 * 034 * <jc>// Or check first:</jc> 035 * <jk>if</jk> (BasicConverter.<jsf>INSTANCE</jsf>.canConvert(String.<jk>class</jk>, Integer.<jk>class</jk>)) { 036 * Integer <jv>x</jv> = BasicConverter.<jsf>INSTANCE</jsf>.to(<js>"42"</js>, Integer.<jk>class</jk>); 037 * } 038 * </p> 039 */ 040public class InvalidConversionException extends RuntimeException { 041 042 private static final long serialVersionUID = 1L; 043 044 /** 045 * Constructor. 046 * 047 * @param inType The runtime type of the input object. 048 * @param outType The target output type. 049 */ 050 public InvalidConversionException(Class<?> inType, Class<?> outType) { 051 super("Cannot convert " + inType.getName() + " to " + outType.getName()); 052 } 053}