Skip to content

Commit 8d7a782

Browse files
committed
Refactor error handling in multiple source files to improve logging and consistency
Signed-off-by: Sathiyamoorthi, Jayabalaji <[email protected]>
1 parent fee584a commit 8d7a782

File tree

7 files changed

+19
-15
lines changed

7 files changed

+19
-15
lines changed

openvino_people_msgs/COLCON_IGNORE

Whitespace-only changes.

openvino_wrapper_lib/include/openvino_wrapper_lib/utils/common.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static UNUSED void printPerformanceCounts(ov::InferRequest request, std::ostream
210210
bool bshowHeader = true)
211211
{
212212
auto performanceMap = request.get_profiling_info();
213-
//printPerformanceCounts(performanceMap, stream, deviceName, bshowHeader);
213+
// printPerformanceCounts(performanceMap, stream, deviceName, bshowHeader);
214214
}
215215

216216
inline std::map<std::string, std::string> getMapFullDevicesNames(ov::Core& core, std::vector<std::string> devices)

openvino_wrapper_lib/src/inputs/realsense_camera.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ bool Input::RealSenseCamera::initialize(size_t width, size_t height)
3030
if (3 * width != 4 * height) {
3131
slog::err << "The aspect ratio must be 4:3 when using RealSense camera" << slog::endl;
3232
throw std::runtime_error("The aspect ratio must be 4:3 when using RealSense camera!");
33-
return false;
3433
}
3534

3635
auto devSerialNumber = getCameraSN();
@@ -63,7 +62,11 @@ bool Input::RealSenseCamera::read(cv::Mat* frame)
6362
cv::Mat(cv::Size(static_cast<int>(getWidth()), static_cast<int>(getHeight())), CV_8UC3,
6463
const_cast<void*>(color_frame.get_data()), cv::Mat::AUTO_STEP)
6564
.copyTo(*frame);
65+
} catch (const std::exception& e) {
66+
slog::err << "RealSense camera read error: " << e.what() << slog::endl;
67+
return false;
6668
} catch (...) {
69+
slog::err << "RealSense camera read error: unknown exception" << slog::endl;
6770
return false;
6871
}
6972

sample/src/image_object_server.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ int main(int argc, char** argv)
4141
auto node = std::make_shared<vino_service::FrameProcessingServer<object_msgs::srv::DetectObject>>(service_name,
4242
config_path);
4343
rclcpp::spin(node);
44-
} catch (std::exception& e) {
45-
std::cout << e.what() << std::endl;
44+
} catch (const std::exception& e) {
45+
slog::err << "[frame_processing_server] Error: " << e.what() << slog::endl;
46+
return -1;
4647
} catch (...) {
47-
std::cout << "[ERROR] [frame_processing_server]: "
48-
<< "exception caught" << std::endl;
48+
slog::err << "[frame_processing_server] Error: Unknown exception caught" << slog::endl;
49+
return -1;
4950
}
5051

5152
return 0;

sample/src/image_people_server.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ int main(int argc, char** argv)
4141
auto node = std::make_shared<vino_service::FrameProcessingServer<object_msgs::srv::People>>(
4242
"service_people_detection", config_path);
4343
rclcpp::spin(node);
44-
} catch (std::exception& e) {
45-
std::cout << e.what() << std::endl;
44+
} catch (const std::exception& e) {
45+
slog::err << "[service_people_detection] Error: " << e.what() << slog::endl;
46+
return -1;
4647
} catch (...) {
47-
std::cout << "[ERROR] [service_people_detection]: "
48-
<< "exception caught" << std::endl;
48+
slog::err << "[service_people_detection] Error: Unknown exception caught" << slog::endl;
49+
return -1;
4950
}
5051

5152
return 0;

sample/src/parameters.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ int main(int argc, char* argv[])
3838
std::string config = getConfigPath(argc, argv);
3939
if (config.empty()) {
4040
throw std::runtime_error("Config File is not correctly set.");
41-
return -1;
4241
}
4342

4443
Params::ParamManager::getInstance().parse(config);
@@ -47,11 +46,11 @@ int main(int argc, char* argv[])
4746
slog::info << "print again, should same as above....." << slog::endl;
4847
Params::ParamManager::getInstance().print();
4948
} catch (const std::exception& error) {
50-
slog::err << error.what() << slog::endl;
49+
slog::err << "Error: " << error.what() << slog::endl;
5150
return -1;
5251
} catch (...) {
5352
slog::err << "Unknown/internal exception happened." << slog::endl;
54-
return -2;
53+
return -1;
5554
}
5655

5756
return 0;

sample/src/pipeline_with_params.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ int main(int argc, char* argv[])
100100
rclcpp::shutdown();
101101

102102
} catch (const std::exception& error) {
103-
slog::err << error.what() << slog::endl;
103+
slog::err << "Pipeline error: " << error.what() << slog::endl;
104104
return -2;
105105
} catch (...) {
106-
slog::err << "Unknown/internal exception happened." << slog::endl;
106+
slog::err << "Pipeline error: Unknown/internal exception happened." << slog::endl;
107107
return -3;
108108
}
109109

0 commit comments

Comments
 (0)