Files
ThreadPilot/docs/reference/EXCEPTION_HANDLING_POLICY.md
T
PrimeBuild-pc c9253f879d Enhance CI/release workflow and app robustness
Add comprehensive CI and release improvements (coverage collection, Codecov upload, SBOM generation), split release workflow into build/smoke-test/release stages with deterministic version resolution, artifact uploads, winget manifest updates and changelog generation. Add a pre-commit hook to block large or unwanted artifacts. Introduce runtime improvements: smoke-test startup mode, improved unhandled/dispatcher/task-exception reporting, ThreadPilotException error codes, single-instance behavior adjustments, and logging enhancements. UI and UX changes include a new Logs tab and LogViewer wiring, DWM title-bar theming helper, navigation serialization/unsaved-changes guard, system-tray update backoff logic, and related viewmodel/service integrations. Also add installer template, helper classes, tests, docs, packaging and build scripts, and minor .gitignore updates.
2026-04-15 22:38:35 +02:00

1.8 KiB

Exception Handling Policy

This policy defines how ThreadPilot handles, classifies, and reports runtime failures.

Goals

  • Prevent silent failures in background tasks.
  • Keep UI responsive when recoverable faults occur.
  • Preserve actionable diagnostics for post-mortem analysis.

Exception Hierarchy

Implemented domain exception tree:

  • ThreadPilotException
  • ProcessManagementException
  • PrivilegeException
  • RuleEngineException
  • ResourceOptimizationException
  • PersistenceException

Each domain exception carries an ErrorCode value for structured logging.

Global Handlers

Global safety net handlers are registered in application startup:

  • AppDomain.CurrentDomain.UnhandledException
  • Application.DispatcherUnhandledException
  • TaskScheduler.UnobservedTaskException

Behavior summary:

  • AppDomain unhandled: critical log + blocking error dialog.
  • Dispatcher unhandled: error log + user choice to continue or terminate.
  • Unobserved task: logged and marked observed to avoid process termination from finalizer escalation.

Logging and Correlation

Unhandled exceptions are routed to:

  • ILogger for immediate diagnostic visibility.
  • IEnhancedLoggingService for persisted structured telemetry.

Structured context includes:

  • Source handler
  • ErrorCode (domain code when available)
  • CorrelationId (if available)
  • Termination-level hint

Recovery Guidelines

  • Prefer local try/catch + retry policies for known transient operations.
  • Use RetryPolicyService with operation-specific predicates.
  • Reserve global handlers for truly unhandled paths only.

Guard Clause Guidelines

  • Validate external inputs at entry points.
  • Throw ArgumentException/ArgumentNullException early for invalid arguments.
  • Wrap domain failures in ThreadPilotException-derived types when crossing service boundaries.