|
1 | 1 | import 'package:flutter_policy_engine/src/exceptions/i_policy_sdk_exceptions.dart';
|
2 | 2 |
|
| 3 | +/// A concrete implementation of [IPolicySDKException] that represents |
| 4 | +/// errors occurring within the Flutter Policy Engine SDK. |
| 5 | +/// |
| 6 | +/// This exception class provides detailed error information including |
| 7 | +/// a descriptive message and an optional underlying exception that |
| 8 | +/// caused the error. It's used throughout the SDK to provide consistent |
| 9 | +/// error handling and reporting. |
| 10 | +/// |
| 11 | +/// Example usage: |
| 12 | +/// ```dart |
| 13 | +/// try { |
| 14 | +/// // SDK operation that might fail |
| 15 | +/// } catch (e) { |
| 16 | +/// throw PolicySDKException( |
| 17 | +/// 'Failed to load policy configuration', |
| 18 | +/// exception: e, |
| 19 | +/// ); |
| 20 | +/// } |
| 21 | +/// ``` |
3 | 22 | class PolicySDKException implements IPolicySDKException {
|
| 23 | + /// Creates a new [PolicySDKException] with the specified error message |
| 24 | + /// and optional underlying exception. |
| 25 | + /// |
| 26 | + /// The [message] should provide a clear, human-readable description |
| 27 | + /// of what went wrong. The [exception] parameter can be used to |
| 28 | + /// preserve the original exception that caused this error, which |
| 29 | + /// is useful for debugging and error tracing. |
| 30 | + /// |
| 31 | + /// Parameters: |
| 32 | + /// - [message]: A descriptive error message explaining what went wrong |
| 33 | + /// - [exception]: An optional underlying exception that caused this error |
4 | 34 | PolicySDKException(
|
5 | 35 | this.message, {
|
6 | 36 | required this.exception,
|
7 | 37 | });
|
8 | 38 |
|
| 39 | + /// A descriptive message explaining the error that occurred. |
| 40 | + /// |
| 41 | + /// This message should be clear enough for developers to understand |
| 42 | + /// what went wrong and potentially how to fix it. |
9 | 43 | @override
|
10 | 44 | final String message;
|
11 | 45 |
|
| 46 | + /// The underlying exception that caused this SDK error, if any. |
| 47 | + /// |
| 48 | + /// This field preserves the original exception for debugging purposes. |
| 49 | + /// It can be null if the error was generated directly by the SDK |
| 50 | + /// without an underlying exception. |
12 | 51 | final Exception? exception;
|
13 | 52 |
|
| 53 | + /// Returns a string representation of this exception. |
| 54 | + /// |
| 55 | + /// The returned string includes the SDK exception message and, |
| 56 | + /// if available, the underlying exception information for debugging. |
| 57 | + /// |
| 58 | + /// Returns: |
| 59 | + /// A formatted string containing the error message and optional |
| 60 | + /// underlying exception details. |
14 | 61 | @override
|
15 | 62 | String toString() {
|
16 | 63 | final buffer = StringBuffer('SDKException: $message');
|
|
0 commit comments