-
Notifications
You must be signed in to change notification settings - Fork 306
/
exceptions.py
138 lines (91 loc) · 2.88 KB
/
exceptions.py
1
2
3
4
5
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"""Exceptions and warnings specific to PlasmaPy."""
__all__ = [
"PlasmaPyError",
"PhysicsError",
"InvalidRomanNumeralError",
"OutOfRangeError",
"RelativityError",
"RomanError",
"PlasmaPyWarning",
"CouplingWarning",
"PhysicsWarning",
"PlasmaPyDeprecationWarning",
"PlasmaPyFutureWarning",
"RelativityWarning",
]
# ------------------------------------------------------------------------------
# Exceptions
# ------------------------------------------------------------------------------
class PlasmaPyError(Exception):
"""
Base class of PlasmaPy custom errors.
All custom exceptions raised by PlasmaPy should inherit from this
class and be defined in this module.
"""
pass
class PhysicsError(PlasmaPyError, ValueError):
"""
The base exception for physics-related errors.
"""
pass
class RomanError(PlasmaPyError):
"""A base exception for errors from `plasmapy.utils.roman`."""
pass
# ^^^^^^^^^^^^ Base Exceptions should be defined above this comment ^^^^^^^^^^^^
class RelativityError(PhysicsError):
"""
An exception for speeds greater than the speed of light.
"""
pass
class OutOfRangeError(RomanError):
"""
An exception to be raised for integers that outside of the range
that can be converted to Roman numerals.
"""
pass
class InvalidRomanNumeralError(RomanError):
"""
An exception to be raised when the input is not a valid Roman
numeral.
"""
pass
# ------------------------------------------------------------------------------
# Warnings
# ------------------------------------------------------------------------------
class PlasmaPyWarning(Warning):
"""
Base class of PlasmaPy custom warnings.
All PlasmaPy custom warnings should inherit from this class and be
defined in this module.
Warnings should be issued using `warnings.warn`, which will not break
execution if unhandled.
"""
pass
class PhysicsWarning(PlasmaPyWarning):
"""The base warning for warnings related to non-physical situations."""
pass
# ^^^^^^^^^^^^^ Base Warnings should be defined above this comment ^^^^^^^^^^^^^
class RelativityWarning(PhysicsWarning):
"""
A warning for when relativistic velocities are being used in or are
returned by non-relativistic functionality.
"""
pass
class CouplingWarning(PhysicsWarning):
"""
A warning for functions that rely on a particular coupling regime to
be valid.
"""
pass
class PlasmaPyDeprecationWarning(PlasmaPyWarning, DeprecationWarning):
"""
A warning for deprecated features when the warning is intended for
other Python developers.
"""
pass
class PlasmaPyFutureWarning(PlasmaPyWarning, FutureWarning):
"""
A warning for deprecated features when the warning is intended for
end users of PlasmaPy.
"""
pass