Exceptions
flaui.lib.exceptions
This module contains the set of custom FlaUI's exceptions.
The Python exceptions mirror the C# FlaUI.Core.Exceptions inheritance tree so that
except clauses behave the same way they do in FlaUI:
.. code-block:: text
Exception
└── FlaUIException
├── ElementNotAvailableException
├── ElementNotEnabledException
├── ElementNotFound (Python-only convenience)
├── MethodNotSupportedException
├── NoClickablePointException
├── NotSupportedByFrameworkException
├── ProxyAssemblyNotLoadedException
├── NotCachedException
│ ├── PatternNotCachedException (carries ``pattern_id``)
│ └── PropertyNotCachedException (carries ``property_id``)
└── NotSupportedException
├── PatternNotSupportedException (carries ``pattern_id``)
└── PropertyNotSupportedException (carries ``property_id``)
SystemException is intentionally kept outside the FlaUIException tree: it wraps a raw
System.Exception that is not a FlaUI error, so except FlaUIException should not catch it.
ElementNotAvailableException(message='Element not available')
Bases: FlaUIException
Python equivalent of C# ElementNotAvailableException (the element is no longer available).
Initialise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
'Element not available'
|
Source code in flaui/lib/exceptions.py
ElementNotEnabledException(message='Element not enabled')
Bases: FlaUIException
Python equivalent of C# ElementNotEnabledException (the element is disabled).
Initialise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
'Element not enabled'
|
Source code in flaui/lib/exceptions.py
ElementNotFound(message='Element not found')
Bases: FlaUIException
Raised when an automation element cannot be found (Python-only convenience, no C# equivalent).
Initialise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
'Element not found'
|
Source code in flaui/lib/exceptions.py
FlaUIException(message='FlaUI exception')
Bases: Exception
Base exception for all FlaUI errors (mirrors C# FlaUI.Core.Exceptions.FlaUIException).
Store the message and initialise the base Exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
'FlaUI exception'
|
Source code in flaui/lib/exceptions.py
MethodNotSupportedException(message='Method not supported')
Bases: FlaUIException
Python equivalent of C# MethodNotSupportedException (the method is not supported).
Initialise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
'Method not supported'
|
Source code in flaui/lib/exceptions.py
NoClickablePointException(message='No clickable point')
Bases: FlaUIException
Python equivalent of C# NoClickablePointException (no clickable point was found).
Initialise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
'No clickable point'
|
Source code in flaui/lib/exceptions.py
NotCachedException(message='Not cached')
Bases: FlaUIException
Python equivalent of C# NotCachedException (requested data was not in the cache).
Initialise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
'Not cached'
|
Source code in flaui/lib/exceptions.py
NotSupportedByFrameworkException(message='Not supported by framework')
Bases: FlaUIException
Python equivalent of C# NotSupportedByFrameworkException (unsupported by the chosen UIA framework).
Initialise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
'Not supported by framework'
|
Source code in flaui/lib/exceptions.py
NotSupportedException(message='Not supported')
Bases: FlaUIException
Python equivalent of C# NotSupportedException (the requested feature is not supported).
Initialise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
'Not supported'
|
Source code in flaui/lib/exceptions.py
PatternNotCachedException(message='The requested pattern is not cached', pattern_id=None)
Bases: NotCachedException
Python equivalent of C# PatternNotCachedException; carries the offending pattern_id.
Initialise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
'The requested pattern is not cached'
|
pattern_id
|
Optional[Any]
|
The C# |
None
|
Source code in flaui/lib/exceptions.py
PatternNotSupportedException(message='The requested pattern is not supported', pattern_id=None)
Bases: NotSupportedException
Python equivalent of C# PatternNotSupportedException; carries the offending pattern_id.
Initialise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
'The requested pattern is not supported'
|
pattern_id
|
Optional[Any]
|
The C# |
None
|
Source code in flaui/lib/exceptions.py
PropertyNotCachedException(message='The requested property is not cached', property_id=None)
Bases: NotCachedException
Python equivalent of C# PropertyNotCachedException; carries the offending property_id.
Initialise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
'The requested property is not cached'
|
property_id
|
Optional[Any]
|
The C# |
None
|
Source code in flaui/lib/exceptions.py
PropertyNotSupportedException(message='The requested property is not supported', property_id=None)
Bases: NotSupportedException
Python equivalent of C# PropertyNotSupportedException; carries the offending property_id.
Initialise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
'The requested property is not supported'
|
property_id
|
Optional[Any]
|
The C# |
None
|
Source code in flaui/lib/exceptions.py
ProxyAssemblyNotLoadedException(message='Proxy assembly not loaded')
Bases: FlaUIException
Python equivalent of C# ProxyAssemblyNotLoadedException (the UIA proxy assembly is missing).
Initialise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
'Proxy assembly not loaded'
|
Source code in flaui/lib/exceptions.py
SystemException(message='System exception')
Bases: Exception
Wraps a raw C# System.Exception that is not a FlaUI error (kept outside the FlaUIException tree).
Initialise the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error description. |
'System exception'
|
Source code in flaui/lib/exceptions.py
handle_csharp_exceptions(func)
Wrap a function so C# FlaUI exceptions are re-raised as their Python equivalents.
The C# exception text is preserved in the re-raised message, and the offending
PropertyId/PatternId is forwarded to property_id/pattern_id where available.
except clauses are ordered most-derived first so subclasses are not swallowed by their base.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
The function to wrap. |
required |
Returns:
| Type | Description |
|---|---|
|
The wrapped function. |
Raises:
| Type | Description |
|---|---|
PropertyNotSupportedException
|
When the C# call raises |
PatternNotSupportedException
|
When the C# call raises |
NotSupportedException
|
When the C# call raises |
PropertyNotCachedException
|
When the C# call raises |
PatternNotCachedException
|
When the C# call raises |
NotCachedException
|
When the C# call raises |
NotSupportedByFrameworkException
|
When the C# call raises |
ProxyAssemblyNotLoadedException
|
When the C# call raises |
NoClickablePointException
|
When the C# call raises |
MethodNotSupportedException
|
When the C# call raises |
ElementNotEnabledException
|
When the C# call raises |
ElementNotAvailableException
|
When the C# call raises |
FlaUIException
|
When the C# call raises any other |
SystemException
|
When the C# call raises a non-FlaUI |
Source code in flaui/lib/exceptions.py
translate_exceptions(arg=None)
Translate C# FlaUI exceptions into their Python equivalents (decorator or context manager).
This is the Pythonic, user-facing entry point. It supports three forms:
.. code-block:: python
# 1. Bare decorator
@translate_exceptions
def do_thing(): ...
# 2. Decorator with a context label
@translate_exceptions("clicking the button")
def click(): ...
# 3. Context manager around an arbitrary block of interop code
with translate_exceptions("reading the value"):
value = element.raw_element.Value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arg
|
Union[Callable[..., Any], str, None]
|
When used as a bare decorator this is the wrapped function; when used as a context manager (or parametrized decorator) this is an optional human-readable context label. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The wrapped function (bare-decorator form) or a context manager that doubles as a parametrized decorator. |