-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(geodata): clarify ServiceException #255
- Loading branch information
1 parent
02d25c1
commit 848a059
Showing
2 changed files
with
31 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 28 additions & 8 deletions
36
dart/geodata/lib/src/common/service/service_exception.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,45 @@ | ||
// Copyright (c) 2020-2023 Navibyte (https://navibyte.com). All rights reserved. | ||
// Copyright (c) 2020-2024 Navibyte (https://navibyte.com). All rights reserved. | ||
// Use of this source code is governed by a “BSD-3-Clause”-style license that is | ||
// specified in the LICENSE file. | ||
// | ||
// Docs: https://github.com/navibyte/geospatial | ||
|
||
/// An exception that could occur when accessing some service. | ||
class ServiceException<T> implements Exception { | ||
/// Create an exception. | ||
import 'package:meta/meta.dart'; | ||
|
||
/// An exception that may occur when accessing app business logic or a service. | ||
/// | ||
/// The required [failure] property provides an app specific failure of the type | ||
/// [T]. | ||
/// | ||
/// An optional source for the exception is provided by [cause] and [trace]. | ||
@immutable | ||
class ServiceException<T extends Object> implements Exception { | ||
/// Create an exception with [failure], and optional [cause] and [trace]. | ||
const ServiceException(this.failure, {this.cause, this.trace}); | ||
|
||
/// The failure as an object of [T]. | ||
/// The app specific failure as an object of [T]. | ||
final T failure; | ||
|
||
/// An optional source that caused the exception. | ||
/// | ||
/// Could be another exception or error instance, or a String object. | ||
/// This could be for example another exception, an error instance or a String | ||
/// object. | ||
final Object? cause; | ||
|
||
/// An optional stack trace that is accociated to an optional [cause]. | ||
/// An optional stack trace that is accociated with an optional [cause]. | ||
final StackTrace? trace; | ||
|
||
@override | ||
String toString() => failure.toString(); | ||
String toString() => '$failure${cause != null ? " ($cause)" : ""}'; | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
identical(this, other) || | ||
(other is ServiceException<T> && | ||
failure == other.failure && | ||
cause == other.cause && | ||
trace == other.trace); | ||
|
||
@override | ||
int get hashCode => Object.hash(failure, cause, trace); | ||
} |