Skip to content

Commit

Permalink
chore: spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
alestiago committed Sep 3, 2024
1 parent 64b1002 commit 5240243
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/content/docs/error_handling/error_handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ This transparency allows developers to handle exceptions properly, leading to mo
<TabItem label="Good ✅">

```dart
/// Deletes permanenetly an account with the given [name].
/// Deletes permanently an account with the given [name].
///
/// Throws:
///
/// * [UnothorizedException] if the active role is not [Role.admin], since only
/// * [UnauthorizedException] if the active role is not [Role.admin], since only
/// admins are authorized to delete accounts.
void deleteAccount(String name) {
if (activeRole != Role.admin) {
throw UnothorizedException('Only admin can delete account');
throw UnauthorizedException('Only admin can delete account');
}
// ...
}
Expand All @@ -31,10 +31,10 @@ void deleteAccount(String name) {
<TabItem label="Bad ❗️">

```dart
/// Deletes permanenetly an account with the given [name].
/// Deletes permanently an account with the given [name].
void deleteAccount(String name) {
if (activeRole != Role.admin) {
throw UnothorizedException('Only admin can delete account');
throw UnauthorizedException('Only admin can delete account');
}
// ...
}
Expand All @@ -43,7 +43,7 @@ void deleteAccount(String name) {
</TabItem>
</Tabs>

## Define implemented exceptions
## Define descriptive exceptions

Implement `Exception` with descriptive names rather than simply throwing a generic `Exception`.

Expand All @@ -53,26 +53,26 @@ By creating custom exceptions, developers can provide more meaningful error mess
<TabItem label="Good ✅">

```dart
class UnothorizedException implements Exception {
UnothorizedException(this.message);
class UnauthorizedException implements Exception {
UnauthorizedException(this.message);
final String message;
@override
String toString() => 'UnothorizedException: $message';
String toString() => 'UnauthorizedException: $message';
}
void deleteAccount(String name) {
if (activeRole != Role.admin) {
throw UnothorizedException('Only admin can delete account');
throw UnauthorizedException('Only admin can delete account');
}
// ...
}
void main() {
try {
deleteAccount('user');
} on UnothorizedException catch (e) {
} on UnauthorizedException catch (e) {
// Handle the exception.
}
}
Expand Down

0 comments on commit 5240243

Please sign in to comment.