Skip to content

incendium.exceptions.ApplicationError

César Román edited this page Apr 30, 2024 · 10 revisions

Class ApplicationError

Syntax

ApplicationError(message, [inner_exception], [cause], [remove_substring])

Args:

  • message (str): The error message.
  • inner_exception (Throwable): The inner Exception. Optional. Defaults to None.
  • cause (str): The cause of the Exception. Optional. Defaults to None.
  • remove_substring (str): The substring to be removed from message. Optional. Defaults to None.

Recommendations

See incendium.exceptions recommendations.

Code Examples

Call from the UI; from a button's actionPerformed code.

from incendium import gui
from incendium.exceptions import ApplicationError

try:
    # Call some function.
    app.some_important_function()
except ApplicationError as exc:
    gui.error(exc.message, "Error")

And the some_important_function would look like this:

import traceback

from incendium import constants, util
from incendium.exceptions import ApplicationError
from java.lang import Exception as JavaException


def some_important_function():
    """Very important function."""
    try:
        # TODO: Do something very important.
        pass
    except JavaException as exc:
        message = constants.UNEXPECTED_ERROR_CAUSED_BY.format(
            util.get_function_name(),
            "\n".join(traceback.format_exc().splitlines()),
            exc.cause,
        )
        raise ApplicationError(message, exc, exc.cause)
    except (IndexError, KeyError) as exc:
        message = constants.UNEXPECTED_ERROR.format(
            util.get_function_name(),
            "\n".join(traceback.format_exc().splitlines()),
        )
        raise ApplicationError(message, exc)
Clone this wiki locally