NetworkException class

Exception for network-related errors.

Use this for HTTP failures, connection issues, DNS errors, etc.

try {
  final response = await http.get(url);
  if (response.statusCode >= 500) {
    throw NetworkException(
      'Server error',
      statusCode: response.statusCode,
    );
  }
} on SocketException catch (e) {
  throw NetworkException('No internet connection', cause: e);
}
Inheritance

Constructors

NetworkException(String message, {int? statusCode, Object? cause, StackTrace? stackTrace})
Creates a NetworkException.
const

Properties

cause Object?
The underlying error that caused this exception, if any.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
isClientError bool
Whether this is a client error (4xx status code).
no setter
isNetworkError bool
Whether this is a network-related error.
no setteroverride
isRetryable bool
Network errors are generally retryable.
no setteroverride
isServerError bool
Whether this is a server error (5xx status code).
no setter
isTimeoutError bool
Whether this is a timeout error.
no setterinherited
isValidationError bool
Whether this is a validation error.
no setterinherited
message String
Human-readable error message.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stackTrace StackTrace?
The stack trace where this exception occurred.
finalinherited
statusCode int?
HTTP status code, if applicable.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited