diff options
author | Petre Eftime <[email protected]> | 2016-04-18 17:23:22 +0300 |
---|---|---|
committer | Petre Eftime <[email protected]> | 2016-04-18 17:23:22 +0300 |
commit | 79303b36dab797614d5f850d418ecfaf2b72d4e7 (patch) | |
tree | 75e25dc854c5300719934be3b45d8680cc943b56 /examples | |
parent | 9eacf541377257799015360f72535a3a5ad636c5 (diff) |
examples: check for exception when instantiating BluetoothManager
Signed-off-by: Petre Eftime <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/asynctinyb.cpp | 10 | ||||
-rw-r--r-- | examples/hellotinyb.cpp | 10 |
2 files changed, 16 insertions, 4 deletions
diff --git a/examples/asynctinyb.cpp b/examples/asynctinyb.cpp index 252da4e8..af41fd55 100644 --- a/examples/asynctinyb.cpp +++ b/examples/asynctinyb.cpp @@ -46,13 +46,19 @@ static float celsius_temp(uint16_t raw_temp) */ int main(int argc, char **argv) { - BluetoothManager *manager = BluetoothManager::get_bluetooth_manager(); - if (argc < 2) { std::cerr << "Run as: " << argv[0] << " <device_address>" << std::endl; exit(1); } + BluetoothManager *manager = nullptr; + try { + manager = BluetoothManager::get_bluetooth_manager(); + } catch(const std::runtime_error& e) { + std::cerr << "Error while initializing libtinyb: " << e.what() << std::endl; + exit(1); + } + /* Start the discovery of devices */ bool ret = manager->start_discovery(); std::cout << "Started = " << (ret ? "true" : "false") << std::endl; diff --git a/examples/hellotinyb.cpp b/examples/hellotinyb.cpp index 59246c83..549b568c 100644 --- a/examples/hellotinyb.cpp +++ b/examples/hellotinyb.cpp @@ -46,13 +46,19 @@ static float celsius_temp(uint16_t raw_temp) */ int main(int argc, char **argv) { - BluetoothManager *manager = BluetoothManager::get_bluetooth_manager(); - if (argc < 2) { std::cerr << "Run as: " << argv[0] << " <device_address>" << std::endl; exit(1); } + BluetoothManager *manager = nullptr; + try { + manager = BluetoothManager::get_bluetooth_manager(); + } catch(const std::runtime_error& e) { + std::cerr << "Error while initializing libtinyb: " << e.what() << std::endl; + exit(1); + } + /* Start the discovery of devices */ bool ret = manager->start_discovery(); std::cout << "Started = " << (ret ? "true" : "false") << std::endl; |