example/pulse: Don't core dump on error
Allowing the defult c++ error handler works to display the error but it
also throws a SIGABRT which triggers coredump logic on the machine
running the example.
diff --git a/example/pulse.cpp b/example/pulse.cpp
index 452e947..15101bb 100644
--- a/example/pulse.cpp
+++ b/example/pulse.cpp
@@ -1,3 +1,4 @@
+#include <exception>
#include <gpioplus/chip.hpp>
#include <gpioplus/handle.hpp>
#include <string>
@@ -10,15 +11,23 @@
return 1;
}
- unsigned chip_id = std::stoi(argv[1]);
- uint32_t line_offset = std::stoi(argv[2]);
+ try
+ {
+ unsigned chip_id = std::stoi(argv[1]);
+ uint32_t line_offset = std::stoi(argv[2]);
- gpioplus::Chip chip(chip_id);
- gpioplus::HandleFlags flags(chip.getLineInfo(line_offset).flags);
- flags.output = true;
- gpioplus::Handle handle(chip, {{line_offset, 0}}, flags, "example/pulse");
- handle.setValues({1});
- handle.setValues({0});
-
- return 0;
+ gpioplus::Chip chip(chip_id);
+ gpioplus::HandleFlags flags(chip.getLineInfo(line_offset).flags);
+ flags.output = true;
+ gpioplus::Handle handle(chip, {{line_offset, 0}}, flags,
+ "example/pulse");
+ handle.setValues({1});
+ handle.setValues({0});
+ return 0;
+ }
+ catch (const std::exception& e)
+ {
+ fprintf(stderr, "Error: %s\n", e.what());
+ }
+ return 1;
}