@@ -172,7 +172,7 @@ def __init__(
172172 mod = ModelicaSystem("ModelicaModel.mo", "modelName", [("Modelica","3.2.3"), "PowerSystems"])
173173 """
174174 if fileName is None and modelName is None and not lmodel : # all None
175- raise Exception ("Cannot create ModelicaSystem object without any arguments" )
175+ raise ModelicaSystemError ("Cannot create ModelicaSystem object without any arguments" )
176176
177177 self .quantitiesList = []
178178 self .paramlist = {}
@@ -219,7 +219,7 @@ def __init__(
219219 self ._raiseerrors = raiseerrors
220220
221221 if self .fileName is not None and not self .fileName .is_file (): # if file does not exist
222- raise IOError (f"File Error: { self .fileName } does not exist!! !" )
222+ raise IOError (f"{ self .fileName } does not exist!" )
223223
224224 # set default command Line Options for linearization as
225225 # linearize() will use the simulation executable and runtime
@@ -327,8 +327,8 @@ def _run_cmd(self, cmd: list, timeout: Optional[int] = None):
327327 logger .info ("OM output for command %s:\n %s" , cmd , stdout )
328328 except subprocess .TimeoutExpired :
329329 raise ModelicaSystemError (f"Timeout running command { repr (cmd )} " )
330- except Exception as e :
331- raise ModelicaSystemError (f"Exception { type ( e ) } running command { cmd } : { e } " )
330+ except Exception as ex :
331+ raise ModelicaSystemError (f"Error running command { cmd } " ) from ex
332332
333333 def _raise_error (self , errstr : str ):
334334 # TODO: raise errors / cleanup / remove this function!
@@ -451,8 +451,8 @@ def getContinuous(self, names=None): # 4
451451 try :
452452 value = self .getSolutions (i )
453453 self .continuouslist [i ] = value [0 ][- 1 ]
454- except Exception :
455- raise ModelicaSystemError (f"OM error: { i } could not be computed" )
454+ except OMCSessionException as ex :
455+ raise ModelicaSystemError (f"{ i } could not be computed" ) from ex
456456 return self .continuouslist
457457
458458 elif isinstance (names , str ):
@@ -461,7 +461,7 @@ def getContinuous(self, names=None): # 4
461461 self .continuouslist [names ] = value [0 ][- 1 ]
462462 return [self .continuouslist .get (names )]
463463 else :
464- raise ModelicaSystemError (f"OM error: { names } is not continuous" )
464+ raise ModelicaSystemError (f"{ names } is not continuous" )
465465
466466 elif isinstance (names , list ):
467467 valuelist = []
@@ -471,7 +471,7 @@ def getContinuous(self, names=None): # 4
471471 self .continuouslist [i ] = value [0 ][- 1 ]
472472 valuelist .append (value [0 ][- 1 ])
473473 else :
474- raise ModelicaSystemError (f"OM error: { i } is not continuous" )
474+ raise ModelicaSystemError (f"{ i } is not continuous" )
475475 return valuelist
476476
477477 raise ModelicaSystemError (f"Unhandled input for getContinous()" )
@@ -731,7 +731,7 @@ def simulate(self, resultfile=None, simflags=None, timeout: Optional[int] = None
731731
732732 exe_file = self .get_exe_file ()
733733 if not exe_file .exists ():
734- raise Exception (f"Error: Application file path not found: { exe_file } " )
734+ raise ModelicaSystemError (f"Application file path not found: { exe_file } " )
735735
736736 cmd = exe_file .as_posix () + override + csvinput + resultfileflag + simflags
737737 cmd = [s for s in cmd .split (' ' ) if s ]
@@ -1113,7 +1113,7 @@ def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = N
11131113 simflags = " " + simflags
11141114
11151115 if not exe_file .exists ():
1116- raise Exception (f"Error: Application file path not found: { exe_file } " )
1116+ raise ModelicaSystemError (f"Application file path not found: { exe_file } " )
11171117 else :
11181118 cmd = exe_file .as_posix () + linruntime + override + csvinput + simflags
11191119 cmd = [s for s in cmd .split (' ' ) if s ]
@@ -1142,8 +1142,8 @@ def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = N
11421142 self .linearstates = stateVars
11431143 return LinearizationResult (n , m , p , A , B , C , D , x0 , u0 , stateVars ,
11441144 inputVars , outputVars )
1145- except ModuleNotFoundError :
1146- raise Exception ( "ModuleNotFoundError: No module named 'linearized_model'" )
1145+ except ModuleNotFoundError as ex :
1146+ raise ModelicaSystemError ( " No module named 'linearized_model'" ) from ex
11471147
11481148 def getLinearInputs (self ):
11491149 """
0 commit comments