|
| 1 | +# Copyright (C) 2024 - 2025 ANSYS, Inc. and/or its affiliates. |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | +# |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | +"""Exceptions module.""" |
| 23 | + |
| 24 | + |
| 25 | +class AnsysError(Exception): |
| 26 | + """Base class for all exceptions raised by the Ansys API. |
| 27 | +
|
| 28 | + Can be used to catch all Ansys-related exceptions. |
| 29 | + """ |
| 30 | + |
| 31 | + def __init__(self, message: str) -> None: |
| 32 | + """Initialize the exception with a message.""" |
| 33 | + super().__init__(message) |
| 34 | + self.message = message |
| 35 | + |
| 36 | + |
| 37 | +class AnsysTypeError(AnsysError): |
| 38 | + """Error raised when an argument is of the wrong type. |
| 39 | +
|
| 40 | + Exception raised when python wise types would work, but internal |
| 41 | + Ansys specific typing is not right. |
| 42 | +
|
| 43 | + Parameters |
| 44 | + ---------- |
| 45 | + expected_type : str | type |
| 46 | + The expected type of the argument. |
| 47 | + actual_type : str | type |
| 48 | + The actual type of the argument. |
| 49 | + """ |
| 50 | + |
| 51 | + def __init__(self, expected_type: str | type, actual_type: str | type = None) -> None: |
| 52 | + """Initialize the exception with expected and actual types.""" |
| 53 | + expected_type = expected_type if isinstance(expected_type, str) else expected_type.__name__ |
| 54 | + actual_type= actual_type if isinstance(actual_type, str) else actual_type.__name__ |
| 55 | + message = f"Expected type {expected_type}, but got {actual_type}." |
| 56 | + super().__init__(message) |
| 57 | + self.expected_type = expected_type |
| 58 | + self.actual_type = actual_type |
| 59 | + |
| 60 | +class AnsysLogicError(AnsysError): |
| 61 | + """Exception raised when an unexpected logical condition occurs. |
| 62 | +
|
| 63 | + Parameters |
| 64 | + ---------- |
| 65 | + message : str |
| 66 | + The error message. |
| 67 | + """ |
| 68 | + |
| 69 | + def __init__(self, message: str) -> None: |
| 70 | + """Initialize the exception with a message.""" |
| 71 | + super().__init__(message) |
0 commit comments