try-catch-finally (Opus)
Dieses Konstrukt erlaubt es, bestimmte Fehler abzufangen und entsprechend zu behandeln. Es wird unterschieden zwischen Fehlern die als Exception behandelbar sind und solchen, die schwere Fehler sind, welche nicht behandelt werden können.
Diese Unterscheidung ist in "Opus Fehlermeldungen" dokumentiert.
Exception Objekt:¶
| Name | Typ | Beschreibung |
|---|---|---|
| OpusError | integer | Fehlercode von Opus |
| ErrorText | string | Text der Opus Fehlermeldung |
| ErrorCode | integer | Erweiterter Fehlercode oder 0, falls nicht verfügbar |
| Location | string | Programmteil der Exception |
| SourceCode | string | Programmzeile auf welcher die Exception aufgetreten ist |
| LineNumber | integer | Zeilennummer der Exception |
| AdditionalInformation | string | Zusatzinformationen, falls vorhanden |
| DateTime | datetime | Zeitstempel |
Beispiel 1:¶
try{ if (condition) throw;} /* try */catch (Lo_Ex) when (Lo_Ex.OpusError == 142) // handle exception only when a condition is true{ // Do something with exception object Lo_Ex} /* catch */catch // multiple catch allowed, Argument and 'when' are optional, catch without condition catches all{ // if not caught by the previous catch if (condition) throw; // rethrow exception} /* catch */finally // 'finally' is optional { // This is always executed} /* finally */