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.junit.bct; 018 019import static org.apache.juneau.junit.bct.Utils.*; 020 021/** 022 * Exception thrown when a requested property cannot be found on an object. 023 * 024 * <p>This exception is typically thrown by {@link PropertyExtractor} implementations 025 * when attempting to access a property that does not exist on the target object.</p> 026 * 027 * <h5 class='section'>Examples:</h5> 028 * <p class='bjava'> 029 * <jc>// Property extraction that may throw PropertyNotFoundException</jc> 030 * <jk>try</jk> { 031 * String <jv>value</jv> = <jv>converter</jv>.getNested(<jv>object</jv>, <jsm>tokenize</jsm>(<js>"nonExistentProperty"</js>).get(0)); 032 * } <jk>catch</jk> (PropertyNotFoundException <jv>e</jv>) { 033 * <jc>// Handle missing property gracefully</jc> 034 * System.<jsm>err</jsm>.println(<js>"Property not found: "</js> + <jv>e</jv>.getMessage()); 035 * } 036 * </p> 037 * 038 * <p class='bjava'> 039 * <jc>// Testing for PropertyNotFoundException</jc> 040 * <jsm>assertThrows</jsm>(PropertyNotFoundException.<jk>class</jk>, () -> { 041 * <jv>converter</jv>.getNested(<jv>bean</jv>, <jsm>tokenize</jsm>(<js>"invalidField"</js>).get(0)); 042 * }); 043 * </p> 044 */ 045public class PropertyNotFoundException extends RuntimeException { 046 047 private static final long serialVersionUID = 1L; 048 049 /** 050 * Constructs a new PropertyNotFoundException with the specified detail message. 051 * 052 * @param message The detail message describing the missing property 053 */ 054 public PropertyNotFoundException(String message) { 055 super(message); 056 } 057 058 /** 059 * Constructs a new PropertyNotFoundException with the specified detail message and cause. 060 * 061 * @param message The detail message describing the missing property 062 * @param cause The underlying cause of the exception 063 */ 064 public PropertyNotFoundException(String message, Throwable cause) { 065 super(message, cause); 066 } 067 068 /** 069 * Constructs a new PropertyNotFoundException for a specific property name and object type. 070 * 071 * @param propertyName The name of the property that could not be found 072 * @param objectType The type of object on which the property was sought 073 */ 074 public PropertyNotFoundException(String propertyName, Class<?> objectType) { 075 super(f("Property ''{0}'' not found on object of type {1}", propertyName, objectType.getSimpleName())); 076 } 077 078 /** 079 * Constructs a new PropertyNotFoundException for a specific property name and object type with a cause. 080 * 081 * @param propertyName The name of the property that could not be found 082 * @param objectType The type of object on which the property was sought 083 * @param cause The underlying cause of the exception 084 */ 085 public PropertyNotFoundException(String propertyName, Class<?> objectType, Throwable cause) { 086 super(f("Property ''{0}'' not found on object of type {1}", propertyName, objectType.getSimpleName()) ,cause); 087 } 088}