In DicomObjects, we don’t throw exceptions when non-zero final status is received during the DICOM associations. The non-zero final status get passed by us and it should be the developers' responsibility to check and, if needed, alert the user for any warnings or failures.

To catch the final status and also the related warning/error fields, you can take a look at the following code (VB6 for COM version and for the .NET version of DicomObjects).


SCP - Setting the Values

 private void Server_InstanceReceived(object Sender, DicomObjects.EventArguments.InstanceReceivedArgs e)
   // For example if There is something wrong with the e.Instance's Patient Name
   // we set the final status to non-zero
   e.Errors.Add(Keyword.OffendingElement, 0x00100010);
   e.Errors.Add(Keyword.ErrorComment, "invalid patient name");
   e.Status = 0xC000;

SCU - Checking the status and populating the information - manually

 DicomAssociation cn;
 // ... ... 
 if (cn.LastStatus != 0)
    int lastStatus = cn.LastStatus;
    string offendingElement = cn.LastCommand[Keyword.OffendingElement].Value.ToString();
    string errorComment = cn.LastCommand[Keyword.ErrorComment].Value.ToString();                

SCU - Using DefaultThrowStatusException

There is a static DicomAssociation property called DefaultThrowStatusException. The default value is false , but if set to true, DicomObjects will throw an exception when a non-zero final status is received, and developers have to put a try catch block to make sure the exception is handled in a proper way.

 DicomAssociation cn;
 // ... 
 cn.ThrowStatusException = true;
    cn.Open("ip", 104, "callingAET", "calledAET");
 catch (Exception ex)
    // exception handling

You can also set the DefaultThrowStatusException behaviour on individual DicomAssociation basis, during the DICOM association.

 DicomAssociation cn;
 // ... 
 cn.Open("ip", 104, "callingAET", "calledAET");
 cn.ThrowStatusException = false;


SCP - Setting the Error Code, Offending Element and Error Comment

It is only possible when using Asynchronous mode in the COM version that you can set the Offending Element Field (0000H, 0901H) and the Error Comment Field (0000H, 0902H):

Private Sub DicomServer1_ImageReceivedAsync(ByVal Connection As DicomObjects.DicomConnection, 
                                            ByVal Image As DicomObjects.DicomImage)
 Connection.Errors.Attributes.Add &H0000, &H0901, &H12345678
 Connection.Errors.Attributes.Add &H0000, &H0902, "My Error Comment"
 Connection.SendStatus &HC000
End Sub

SCU - Checking the Final Status and Populating the Offending Element and Error Comment

Keep in mind Offending Element and Error Comment are optional, so they may or may not be present in the returned response. You need to make sure they are present before trying to access their values.

Dim v as Variant
Dim list as String
' cn here is a DicomConnection object, you check the returned final status after an operation, i.e. SendImages
If cn.LastStatus <> 0 Then
  If cn.ReturnedResponses(cn.ReturnedResponses.Count).Attributes(&H0, &H901).Exists And 
     cn.ReturnedResponses(cn.ReturnedResponses.Count).Attributes(&H0, &H901).Value <>  Nothing Then
    v = cn.ReturnedResponses(cn.ReturnedResponses.Count).Attributes(&H0, &H901).Value
    If (VarType(v) > 8192) Then ' We expect an array here
       For i = LBound(v, 1) To UBound(v, 1)
          list = list & Hex(v(i))
    End If
    MsgBox "LastStatus - " & cn.LastStatus
    MsgBox "Error Element - " & list
    MsgBox "Error Comment - " & cn.ReturnedResponses(cn.ReturnedResponses.Count).Attributes(&H0, &H902).Value
  End If
End If