fltk.error
FLTK Error Handling and Exception Types
This module provides a centralized error handling framework for the FLTK high-level D API. It defines a hierarchy of exception types for different error categories and utilities for error translation.
Exception Hierarchy:
Exception
└── FltkException (base for all FLTK errors)
├── InvalidHandleException (null/invalid handle)
├── WindowException (window creation/operation)
├── ImageException (image loading/processing)
│ └── ImageLoadException (file loading)
└── GlException (OpenGL context errors)Ownership Model:
- RAII classes (Window, Button, etc.) own their handles
- Destructors automatically free resources
- Widgets added to Groups transfer ownership to the parent
- Use
release()to detach handle without destruction
Threading Model:
- FLTK is primarily single-threaded (main thread only)
- All widget operations must occur on the main thread
- Use
lock()/unlock()from app module for multi-threaded access - Background threads should use
awake()to signal main threadLicense
BSD-3-ClauseCopyright
Copyright © 2025 DDN (D Developer Network) Members
Module Initializers 1
()Types 7
Base exception class for all FLTK-related errors.
All FLTK exceptions inherit from this class, allowing callers to catch all FLTK errors with a single catch clause if desired.
Example:
try {
auto window = new Window(800, 600, "Test");
} catch (FltkException e) {
writeln("FLTK error: ", e.msg);
}this(string msg, string file = __FILE__, size_t line = __LINE__)Constructs an FltkException with the given message.Exception thrown when an invalid or null handle is used.
This exception indicates an attempt to perform an operation on a widget or resource that has already been destroyed or was never properly initialized.
Example:
Widget w = null;
if (w is null) {
throw new InvalidHandleException("Widget handle is null");
}this(string msg = "Invalid or null handle", string file = __FILE__, size_t line = __LINE__)Constructs an InvalidHandleException.Exception thrown for window creation or operation failures.
This exception indicates that a window could not be created or a window operation failed (e.g., showing a window without a display).
Exception thrown when image loading fails.
This exception provides details about why an image could not be loaded, including the filename and error code.
string filenameThe filename that failed to load (if applicable)int errorCodeThe error code from FLTK (0 = OK)this(string msg, string filename = null, int errorCode = 0,
string file = __FILE__, size_t line = __LINE__)Constructs an ImageLoadException.Exception thrown for OpenGL-related errors.
This exception indicates OpenGL context creation failures or other GL-specific errors.
this(string msg = "OpenGL operation failed", string file = __FILE__, size_t line = __LINE__)Constructs a GlException.Image error codes from FLTK.
These match the values returned by FLTK image loading functions.
Functions 6
string imageErrorMessage(int code) pure nothrow @safeConverts an image error code to a human-readable message.void enforceImageLoad(int errorCode, string filename = null)Throws an ImageLoadException if the error code indicates failure.void enforceValidHandle(T)(T handle, string msg = "Invalid or null handle")Enforces that a handle is not null.void enforceMainThread(string operation = "FLTK operation")Enforces that the current thread is the main thread.void debugAssert(bool condition, lazy string msg = "Assertion failed")Asserts a condition in debug builds only.