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#ifdef HAVE_XPETRA_EPETRA
34#define XPETRA_FACTORY_ERROR_IF_EPETRA(lib) \
35 if ((lib) == ::Xpetra::UseEpetra) \
36 TEUCHOS_TEST_FOR_EXCEPTION(1, ::Xpetra::Exceptions::BadCast, "Epetra can only be used with Scalar=double and LocalOrdinal=GlobalOrdinal=int on a serial node");
37#else
38#define XPETRA_FACTORY_ERROR_IF_EPETRA(lib)
39#endif
40
41#define XPETRA_FACTORY_END TEUCHOS_TEST_FOR_EXCEPTION(1, ::Xpetra::Exceptions::BadCast, "Unknown map->lib() type. Did you compile with Epetra and Tpetra support?");
42
43#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.");
44
45namespace Xpetra {
46namespace Exceptions {
47
49
51 public:
52 BadCast(const std::string& what_arg)
53 : Teuchos::ExceptionBase(what_arg) {}
54};
55
57
59 public:
60 NotImplemented(const std::string& what_arg)
61 : Teuchos::ExceptionBase(what_arg) {}
62};
63
66 public:
67 RuntimeError(const std::string& what_arg)
68 : Teuchos::ExceptionBase(what_arg) {}
69};
70
73 public:
74 Incompatible(const std::string& what_arg)
75 : Teuchos::ExceptionBase(what_arg) {}
76};
77
78} // namespace Exceptions
79} // namespace Xpetra
80
81#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)