Skip to content

Commit 982ab8f

Browse files
committed
[TracerRealTime] Fix addSignalToTrace for exception handling
1 parent 57f773f commit 982ab8f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/traces/tracer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,12 @@ Tracer::Tracer(const std::string n)
8888
void Tracer::addSignalToTrace(const SignalBase<int> &sig,
8989
const string &filename) {
9090
dgDEBUGIN(15);
91+
// openFile may throw so it should be called first.
92+
if (namesSet)
93+
openFile(sig, filename);
9194
toTraceSignals.push_back(&sig);
9295
dgDEBUGF(15, "%p", &sig);
9396
names.push_back(filename);
94-
if (namesSet)
95-
openFile(sig, filename);
9697
triger.addDependency(sig);
9798
dgDEBUGOUT(15);
9899
}

tests/debug-real-time-tracer.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,16 @@ BOOST_AUTO_TEST_CASE(test_tracer) {
6565
std::string basename("my-tracer");
6666
std::string suffix(".dat");
6767

68-
/// Test openfiles
6968
atracer.setBufferSize(1<<14);
70-
atracer.openFiles(rootdir, basename, suffix);
7169

72-
/// Add trace by name
70+
// Check that an exception is thrown if the filename is invalid.
71+
atracer.openFiles(rootdir, "invalid/filename", suffix);
72+
BOOST_CHECK_THROW(atracer.addSignalToTraceByName("my-entity.out_double", "output"),
73+
ExceptionTraces);
74+
75+
// Test openfiles
76+
atracer.openFiles(rootdir, basename, suffix);
77+
// Add trace by name
7378
atracer.addSignalToTraceByName("my-entity.out_double", "output");
7479

7580
/// Add trace by name

0 commit comments

Comments
 (0)