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 thread

    Authors

    Dejan Lekić

    License

    BSD-3-Clause

Module Initializers 1

shared static this()

Types 7

classFltkException : Exception

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);
}

Constructors
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");
}

Constructors
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).

Constructors
this(string msg = "Window operation failed", string file = __FILE__, size_t line = __LINE__)Constructs a WindowException.

Base exception for image-related errors.

This is the base class for all image processing exceptions.

Constructors
this(string msg = "Image operation failed", string file = __FILE__, size_t line = __LINE__)Constructs an ImageException.

Exception thrown when image loading fails.

This exception provides details about why an image could not be loaded, including the filename and error code.

Fields
string filenameThe filename that failed to load (if applicable)
int errorCodeThe error code from FLTK (0 = OK)
Constructors
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.

Constructors
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.

OK = 0Image loaded successfully
FILE_NOT_FOUND = 1File not found or cannot be opened
INVALID_DATA = 2Invalid or corrupt image data
UNSUPPORTED_FORMAT = 3Unsupported image format
OUT_OF_MEMORY = 4Memory allocation failed

Functions 6

fnstring imageErrorMessage(int code) pure nothrow @safeConverts an image error code to a human-readable message.
fnvoid enforceImageLoad(int errorCode, string filename = null)Throws an ImageLoadException if the error code indicates failure.
fnvoid enforceValidHandle(T)(T handle, string msg = "Invalid or null handle")Enforces that a handle is not null.
fnbool isMainThread() nothrow @trustedChecks if the current thread is the main thread.
fnvoid enforceMainThread(string operation = "FLTK operation")Enforces that the current thread is the main thread.
fnvoid debugAssert(bool condition, lazy string msg = "Assertion failed")Asserts a condition in debug builds only.

Variables 1

private varThread _mainThread