Xpetra Version of the Day
Loading...
Searching...
No Matches
Xpetra_Exceptions.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Xpetra: A linear algebra interface package
4//
5// Copyright 2012 NTESS and the Xpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef XPETRA_EXCEPTIONS_HPP
11#define XPETRA_EXCEPTIONS_HPP
12
13#include <exception>
14#include <Teuchos_Exceptions.hpp>
15#include <Teuchos_Assert.hpp>
16
17#include "Xpetra_ConfigDefs.hpp"
18
19// Dynamically cast 'obj' to 'type newObj'. newObj is declared inside of the macro.
20// If the dynamic cast failed, throw an exception of type Xpetra::Exception::Bad_Cast (using the message exceptionMsg).
21#define XPETRA_COMMA ,
22#define XPETRA_DYNAMIC_CAST(type, obj, newObj, exceptionMsg) \
23 type* newObj##_pt = dynamic_cast<type*>(&obj); \
24 TEUCHOS_TEST_FOR_EXCEPTION(newObj##_pt == NULL, Xpetra::Exceptions::BadCast, "Cannot cast '" #obj "' to a " #type ". " #exceptionMsg); \
25 type& newObj = *newObj##_pt;
26
27// Dynamically cast the RCP 'obj' to 'RCP<type> newObj'. newObj is declared inside of the macro.
28// If the dynamic cast failed, throw an exception of type Xpetra::Exception::Bad_Cast (using the message exceptionMsg).
29#define XPETRA_RCP_DYNAMIC_CAST(type, obj, newObj, exceptionMsg) \
30 const RCP<type>& newObj = Teuchos::rcp_dynamic_cast<type>(obj); \
31 TEUCHOS_TEST_FOR_EXCEPTION(newObj == Teuchos::null, Xpetra::Exceptions::BadCast, "Cannot cast '" #obj "' to a " #type ". " #exceptionMsg);
32
33#define XPETRA_FACTORY_END TEUCHOS_TEST_FOR_EXCEPTION(1, ::Xpetra::Exceptions::BadCast, "Unknown map->lib() type. Did you compile with Epetra and Tpetra support?");
34
35#define XPETRA_TPETRA_ETI_EXCEPTION(cl, obj, go, node) TEUCHOS_TEST_FOR_EXCEPTION(1, ::Xpetra::Exceptions::BadCast, "Problem in " #cl "! Cannot create new object " #obj " with GO=" #go " and NO=" #node ". Xpetra has been compiled with Tpetra enabled but GO=" #go " disabled and/or NO=" #node " disabled. Please check your Trilinos configuration.");
36
37namespace Xpetra {
38namespace Exceptions {
39
41
43 public:
44 BadCast(const std::string& what_arg)
45 : Teuchos::ExceptionBase(what_arg) {}
46};
47
49
51 public:
52 NotImplemented(const std::string& what_arg)
53 : Teuchos::ExceptionBase(what_arg) {}
54};
55
58 public:
59 RuntimeError(const std::string& what_arg)
60 : Teuchos::ExceptionBase(what_arg) {}
61};
62
65 public:
66 Incompatible(const std::string& what_arg)
67 : Teuchos::ExceptionBase(what_arg) {}
68};
69
70} // namespace Exceptions
71} // namespace Xpetra
72
73#endif
Exception indicating invalid cast attempted.
BadCast(const std::string &what_arg)
Exception throws to report incompatible objects (like maps).
Incompatible(const std::string &what_arg)
Exception throws when you call an unimplemented method of Xpetra.
NotImplemented(const std::string &what_arg)
Exception throws to report errors in the internal logical of the program.
RuntimeError(const std::string &what_arg)