Skip to content

Commit ff320b8

Browse files
authored
Check exception status even if TF_SessionRun throws an exception (#4755)
1 parent 47c49ff commit ff320b8

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/Microsoft.ML.TensorFlow/TensorflowUtils.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using System.Collections.Generic;
76
using System.IO;
87
using System.Linq;
98
using System.Security.AccessControl;
@@ -488,9 +487,26 @@ public Tensor[] Run()
488487

489488
unsafe
490489
{
491-
c_api.TF_SessionRun(_session, null, _inputs, _inputValues,
492-
_inputs.Length, _outputs, _outputValues, _outputValues.Length, _operations,
493-
_operations.Length, IntPtr.Zero, _status);
490+
try
491+
{
492+
c_api.TF_SessionRun(_session, null, _inputs, _inputValues,
493+
_inputs.Length, _outputs, _outputValues, _outputValues.Length, _operations,
494+
_operations.Length, IntPtr.Zero, _status);
495+
}
496+
catch (Exception ex)
497+
{
498+
try
499+
{
500+
_status.Check(throwException: true);
501+
}
502+
catch (Exception statusException)
503+
{
504+
throw new AggregateException(statusException, ex);
505+
}
506+
507+
// _status didn't provide more information, so just rethrow the original exception
508+
throw;
509+
}
494510
}
495511

496512
_status.Check(true);

0 commit comments

Comments
 (0)