Commit 9be79a27c3cd902ee12d2e58f1e4969966ee9fbe

Authored by knodlseder
1 parent 5dd9aafc

Add exceptions for CTA response table checking.

inst/cta/include/GCTAException.hpp
... ... @@ -125,6 +125,20 @@ public:
125 125 model_invalid_radial(std::string origin, std::string type,
126 126 std::string message = "");
127 127 };
  128 +
  129 + // Response table exceptions
  130 + class bad_rsp_table_dim : public GCTAExceptionHandler {
  131 + public:
  132 + bad_rsp_table_dim(std::string origin,
  133 + int table_dim,
  134 + int expected_dim,
  135 + std::string message = "");
  136 + };
  137 + class bad_rsp_table_format : public GCTAExceptionHandler {
  138 + public:
  139 + bad_rsp_table_format(std::string origin,
  140 + std::string message = "");
  141 + };
128 142 };
129 143  
130 144 #endif /* GCTAEXCEPTION_HPP */
... ...
inst/cta/src/GCTAException.cpp
1 1 /***************************************************************************
2 2 * GCTAException.cpp - CTA exception handler *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2011 by Jurgen Knodlseder *
  4 + * copyright (C) 2010-2012 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -21,7 +21,7 @@
21 21 /**
22 22 * @file GCTAException.cpp
23 23 * @brief CTA exception handler interface implementation.
24   - * @author J. Knodlseder
  24 + * @author J. Knoedlseder
25 25 */
26 26  
27 27 /* __ Includes ___________________________________________________________ */
... ... @@ -327,17 +327,69 @@ GCTAException::model_invalid_radial::model_invalid_radial(std::string origin,
327 327 if (registry.size() > 0) {
328 328 m_message += "The following models are registered: ";
329 329 for (int i = 0; i < registry.size(); ++i) {
330   - if (i > 0)
  330 + if (i > 0) {
331 331 m_message += ", ";
  332 + }
332 333 m_message += "\"" + registry.name(i) + "\"";
333 334 }
334 335 m_message += ".";
335 336 }
336   - else
  337 + else {
337 338 m_message += "No models are registered.";
  339 + }
338 340  
339 341 // Return
340 342 return;
341 343 }
342 344  
343 345  
  346 +/***********************************************************************//**
  347 + * @brief Bad response table dimension
  348 + *
  349 + * @param[in] origin Name of method that has thrown the exception.
  350 + * @param[in] found Found table dimension.
  351 + * @param[in] expected Expected table dimension.
  352 + * @param[in] message Optional error message.
  353 + ***************************************************************************/
  354 +GCTAException::bad_rsp_table_dim::bad_rsp_table_dim(std::string origin,
  355 + int found,
  356 + int expected,
  357 + std::string message)
  358 +{
  359 + // Set origin
  360 + m_origin = origin;
  361 +
  362 + // Set message
  363 + m_message = "Response table dimension "+str(found)+
  364 + " is smaller than the expected dimension "+str(expected)+
  365 + ".";
  366 + if (message.length() > 0) {
  367 + m_message += " "+message;
  368 + }
  369 +
  370 + // Return
  371 + return;
  372 +}
  373 +
  374 +
  375 +/***********************************************************************//**
  376 + * @brief Bad response table format
  377 + *
  378 + * @param[in] origin Name of method that has thrown the exception.
  379 + * @param[in] message Optional error message.
  380 + ***************************************************************************/
  381 +GCTAException::bad_rsp_table_format::bad_rsp_table_format(std::string origin,
  382 + std::string message)
  383 +{
  384 + // Set origin
  385 + m_origin = origin;
  386 +
  387 + // Set message
  388 + m_message = "Response table has invalid format.";
  389 + if (message.length() > 0) {
  390 + m_message += " "+message;
  391 + }
  392 +
  393 + // Return
  394 + return;
  395 +}
... ...