Skip to content

Register now for

# Reference for `hub_sdk/helpers/exceptions.py`

Note

This file is available at https://github.com/ultralytics/hub-sdk/blob/main/hub_sdk/helpers/exceptions.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!

## `` hub_sdk.helpers.exceptions.suppress_exceptions

    suppress_exceptions() -> None

Suppress exceptions locally based on the global HUB_EXCEPTIONS flag.

If the HUB_EXCEPTIONS flag is set to False, this function raises the caught exception, allowing it to propagate and be handled elsewhere. If the flag is set to True, the function suppresses the exception, effectively handling it locally.

Examples:

### Set the HUB_EXCEPTIONS constant to control exception handling globally

    >>> HUB_EXCEPTIONS = False

    >>> try:
    ...     # Your code that may raise an exception
    ...     pass
    ... except ValueError as e:
    ...     # The exception will be suppressed if HUB_EXCEPTIONS is True
    ...     suppress_exceptions()
    ...     # Exception handling continues here if HUB_EXCEPTIONS is False

Notes

This function is designed to be used in conjunction with the global HUB_EXCEPTIONS constant to control exception handling behavior across multiple parts of the codebase.

Source code in `hub_sdk/helpers/exceptions.py`

     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    def suppress_exceptions() -> None:
        """
        Suppress exceptions locally based on the global HUB_EXCEPTIONS flag.

        If the HUB_EXCEPTIONS flag is set to False, this function raises the caught exception,
        allowing it to propagate and be handled elsewhere. If the flag is set to True,
        the function suppresses the exception, effectively handling it locally.

        Examples:
            # Set the HUB_EXCEPTIONS constant to control exception handling globally
            >>> HUB_EXCEPTIONS = False

            >>> try:
            ...     # Your code that may raise an exception
            ...     pass
            ... except ValueError as e:
            ...     # The exception will be suppressed if HUB_EXCEPTIONS is True
            ...     suppress_exceptions()
            ...     # Exception handling continues here if HUB_EXCEPTIONS is False

        Notes:
            This function is designed to be used in conjunction with the global HUB_EXCEPTIONS constant
            to control exception handling behavior across multiple parts of the codebase.
        """
        if not HUB_EXCEPTIONS:
            raise

📅 Created 1 year ago ✏️ Updated 1 month ago