@@ -43,7 +43,7 @@ def __str__(self):
4343 return f'(#{ self .args [0 ]} ) { self .args [1 ]} '
4444
4545
46- # For backwards compatibility
46+ # For backwards compatibility, will be removed for version 1.0
4747DssException = DSSException
4848use_com_compat = set_case_insensitive_attributes
4949
@@ -105,6 +105,8 @@ class Base:
105105 '_errorPtr' ,
106106 ]
107107
108+ _use_exceptions = True
109+
108110 def __init__ (self , api_util ):
109111 self ._lib = api_util .lib
110112 self ._api_util = api_util
@@ -137,9 +139,39 @@ def __init__(self, api_util):
137139 cls ._dss_attributes = lowercase_map
138140
139141
142+ @staticmethod
143+ def _enable_exceptions (do_enable : bool ):
144+ """
145+ Controls whether the automatic error checking mechanism is enable, i.e., if
146+ the DSS engine errors (from the `Error` interface) are mapped exception when
147+ detected.
148+
149+ **When disabled, the user takes responsibility for checking for errors.**
150+ This can be done through the `Error` interface. When `Error.Number` is not
151+ zero, there should be an error message in `Error.Description`. This is compatible
152+ with the behavior on the official OpenDSS (Windows-only COM implementation) when
153+ `AllowForms` is disabled.
154+
155+ Users can also use the DSS command `Export ErrorLog` to inspect for errors.
156+
157+ **WARNING:** This is a global setting, affects all DSS instances from DSS-Python
158+ and OpenDSSDirect.py.
159+ """
160+ Base ._use_exceptions = bool (do_enable )
161+
140162 def _check_for_error (self , result = None ):
141- '''Checks for an OpenDSS error. Raises an exception if any, otherwise returns the `result` parameter.'''
142- if self ._errorPtr [0 ]:
163+ """
164+ Checks for a DSS engine error (on the default configuration).
165+
166+ By default, raises an exception if any error is detected, otherwise returns the `result` parameter.
167+
168+ If the user disabled exceptions, any error is simply ignored. Note that, in this case, manually
169+ calling this function would have no purpose/effects.
170+
171+ Note that, **in the future**, we may try showing a popup form like the official OpenDSS does on Windows
172+ if AllowForms is True. This behavior is not very portable though and not adequate for automated scripts.
173+ """
174+ if self ._errorPtr [0 ] and Base ._use_exceptions :
143175 error_num = self ._errorPtr [0 ]
144176 self ._errorPtr [0 ] = 0
145177 raise DSSException (error_num , self ._get_string (self ._lib .Error_Get_Description ()))
0 commit comments