|
33 | 33 | #include <optional> |
34 | 34 | #include <stdexcept> |
35 | 35 | #include <sstream> |
| 36 | +#include <vector> |
36 | 37 | #include "ur/version_information.h" |
| 38 | +#include "ur_client_library/ur/datatypes.h" |
37 | 39 |
|
38 | 40 | #ifdef _WIN32 |
39 | 41 | # define NOMINMAX |
@@ -336,5 +338,133 @@ class ScriptCodeSyntaxException : public UrException |
336 | 338 | return std::runtime_error::what(); |
337 | 339 | } |
338 | 340 | }; |
| 341 | + |
| 342 | +class RobotModeException : public UrException |
| 343 | +{ |
| 344 | +public: |
| 345 | + explicit RobotModeException() = delete; |
| 346 | + |
| 347 | + explicit RobotModeException(const std::string& operation, const RobotMode& required, const RobotMode& actual) |
| 348 | + : std::runtime_error("Incorrect robot mode: " + robotModeString(actual)) |
| 349 | + { |
| 350 | + std::stringstream ss; |
| 351 | + ss << "Robot is in incorrect mode for the requested operation: " << operation << "\n" |
| 352 | + << "Required robot mode: " << urcl::robotModeString(required) << " (" << int(required) << ") \n" |
| 353 | + << "Actual robot mode: " << urcl::robotModeString(actual) << " (" << int(actual) << ")"; |
| 354 | + text_ = ss.str(); |
| 355 | + } |
| 356 | + |
| 357 | + virtual ~RobotModeException() = default; |
| 358 | + |
| 359 | + virtual const char* what() const noexcept override |
| 360 | + { |
| 361 | + return text_.c_str(); |
| 362 | + } |
| 363 | + |
| 364 | +private: |
| 365 | + std::string text_; |
| 366 | +}; |
| 367 | + |
| 368 | +class SafetyModeException : public UrException |
| 369 | +{ |
| 370 | +public: |
| 371 | + explicit SafetyModeException() = delete; |
| 372 | + |
| 373 | + explicit SafetyModeException(const std::string& operation, const std::vector<urcl::SafetyMode>& options, |
| 374 | + const urcl::SafetyMode& actual) |
| 375 | + : std::runtime_error("Incorrect safety mode: " + safetyModeString(actual)) |
| 376 | + { |
| 377 | + std::stringstream ss; |
| 378 | + ss << "Robot is in incorrect safety mode for the requested operation: " << operation << "\n" |
| 379 | + << "Safety mode should be one of: \n"; |
| 380 | + |
| 381 | + for (auto mode : options) |
| 382 | + { |
| 383 | + ss << urcl::safetyModeString(mode) << " (" << int(mode) << ")\n"; |
| 384 | + } |
| 385 | + ss << "\n" |
| 386 | + << "Actual safety mode: " << urcl::safetyModeString(actual) << " (" << int(actual) << ")"; |
| 387 | + text_ = ss.str(); |
| 388 | + } |
| 389 | + |
| 390 | + virtual ~SafetyModeException() = default; |
| 391 | + |
| 392 | + virtual const char* what() const noexcept override |
| 393 | + { |
| 394 | + return text_.c_str(); |
| 395 | + } |
| 396 | + |
| 397 | +private: |
| 398 | + std::string text_; |
| 399 | +}; |
| 400 | + |
| 401 | +class StreamNotConnectedException : public UrException |
| 402 | +{ |
| 403 | +public: |
| 404 | + explicit StreamNotConnectedException() = delete; |
| 405 | + |
| 406 | + explicit StreamNotConnectedException(const std::string& text) : std::runtime_error(text) |
| 407 | + { |
| 408 | + } |
| 409 | + |
| 410 | + virtual ~StreamNotConnectedException() = default; |
| 411 | + |
| 412 | + virtual const char* what() const noexcept override |
| 413 | + { |
| 414 | + return std::runtime_error::what(); |
| 415 | + } |
| 416 | +}; |
| 417 | + |
| 418 | +class RobotRuntimeException : public UrException |
| 419 | +{ |
| 420 | +public: |
| 421 | + explicit RobotRuntimeException() = delete; |
| 422 | + |
| 423 | + explicit RobotRuntimeException(const std::string& text) : std::runtime_error(text) |
| 424 | + { |
| 425 | + } |
| 426 | + |
| 427 | + virtual ~RobotRuntimeException() = default; |
| 428 | + |
| 429 | + virtual const char* what() const noexcept override |
| 430 | + { |
| 431 | + return std::runtime_error::what(); |
| 432 | + } |
| 433 | +}; |
| 434 | + |
| 435 | +class ReadOnlyInterfaceException : public UrException |
| 436 | +{ |
| 437 | +public: |
| 438 | + explicit ReadOnlyInterfaceException() = delete; |
| 439 | + |
| 440 | + explicit ReadOnlyInterfaceException(const std::string& text) : std::runtime_error(text) |
| 441 | + { |
| 442 | + } |
| 443 | + |
| 444 | + virtual ~ReadOnlyInterfaceException() = default; |
| 445 | + |
| 446 | + virtual const char* what() const noexcept override |
| 447 | + { |
| 448 | + return std::runtime_error::what(); |
| 449 | + } |
| 450 | +}; |
| 451 | + |
| 452 | +class RobotErrorCodeException : public UrException |
| 453 | +{ |
| 454 | +public: |
| 455 | + explicit RobotErrorCodeException() = delete; |
| 456 | + |
| 457 | + explicit RobotErrorCodeException(const std::string& text) : std::runtime_error(text) |
| 458 | + { |
| 459 | + } |
| 460 | + |
| 461 | + virtual ~RobotErrorCodeException() = default; |
| 462 | + |
| 463 | + virtual const char* what() const noexcept override |
| 464 | + { |
| 465 | + return std::runtime_error::what(); |
| 466 | + } |
| 467 | +}; |
| 468 | + |
339 | 469 | } // namespace urcl |
340 | 470 | #endif // ifndef UR_CLIENT_LIBRARY_EXCEPTIONS_H_INCLUDED |
0 commit comments