class FolderNotFound
A custom exception class that is raised when a requested folder cannot be found in the system.
/tf/active/vicechatdev/rmcl/exceptions.py
22 - 25
simple
Purpose
This exception class provides a specific error type for folder-not-found scenarios, allowing calling code to distinguish folder lookup failures from other types of exceptions. It extends Python's built-in Exception class and accepts a custom error message to provide context about which folder was not found.
Source Code
class FolderNotFound(Exception):
"""Could not found a requested folder"""
def __init__(self, msg):
super(FolderNotFound, self).__init__(msg)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
Exception | - |
Parameter Details
msg: A string message describing the folder that was not found. This message is passed to the parent Exception class and will be displayed when the exception is raised or converted to a string. Should typically include the folder path or name that was being searched for.
Return Value
Instantiation returns a FolderNotFound exception object that can be raised using the 'raise' keyword. When caught, the exception object contains the error message accessible via str(exception) or exception.args[0].
Class Interface
Methods
__init__(self, msg: str) -> None
Purpose: Initializes the FolderNotFound exception with a custom error message
Parameters:
msg: A string message describing which folder was not found and providing context for the error
Returns: None (constructor)
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
args |
tuple | Inherited from Exception base class. Contains the error message as a tuple element, accessible via args[0] | instance |
Usage Example
# Example 1: Raising the exception
import os
def get_folder_contents(folder_path):
if not os.path.exists(folder_path):
raise FolderNotFound(f"Folder '{folder_path}' does not exist")
return os.listdir(folder_path)
# Example 2: Catching the exception
try:
contents = get_folder_contents('/nonexistent/path')
except FolderNotFound as e:
print(f"Error: {e}")
# Handle the missing folder case
# Example 3: Direct instantiation and raising
error = FolderNotFound("The data folder could not be located")
raise error
Best Practices
- Always provide a descriptive message when raising this exception, including the folder path or name that was not found
- Use this exception specifically for folder/directory lookup failures rather than generic file operations
- Catch this exception specifically when you want to handle folder-not-found cases differently from other exceptions
- Consider including the full path in the error message to aid debugging
- This exception should be raised before attempting operations that require the folder to exist
- Can be used in conjunction with os.path.exists() or pathlib.Path.exists() checks
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class DocumentNotFound 72.4% similar
-
class ResourceNotFoundError_v1 63.6% similar
-
class ResourceNotFoundError 61.0% similar
-
class UnsupportedTypeError 56.0% similar
-
class PermissionError_v1 53.7% similar