Multiscale Universal Interface  2.0
A Concurrent Framework for Coupling Heterogeneous Solvers
exception.h
Go to the documentation of this file.
1 /*****************************************************************************
2 * Multiscale Universal Interface Code Coupling Library *
3 * *
4 * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis *
5 * *
6 * This software is jointly licensed under the Apache License, Version 2.0 *
7 * and the GNU General Public License version 3, you may use it according *
8 * to either. *
9 * *
10 * ** Apache License, version 2.0 ** *
11 * *
12 * Licensed under the Apache License, Version 2.0 (the "License"); *
13 * you may not use this file except in compliance with the License. *
14 * You may obtain a copy of the License at *
15 * *
16 * http://www.apache.org/licenses/LICENSE-2.0 *
17 * *
18 * Unless required by applicable law or agreed to in writing, software *
19 * distributed under the License is distributed on an "AS IS" BASIS, *
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
21 * See the License for the specific language governing permissions and *
22 * limitations under the License. *
23 * *
24 * ** GNU General Public License, version 3 ** *
25 * *
26 * This program is free software: you can redistribute it and/or modify *
27 * it under the terms of the GNU General Public License as published by *
28 * the Free Software Foundation, either version 3 of the License, or *
29 * (at your option) any later version. *
30 * *
31 * This program is distributed in the hope that it will be useful, *
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
34 * GNU General Public License for more details. *
35 * *
36 * You should have received a copy of the GNU General Public License *
37 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
38 *****************************************************************************/
39 
47 #ifndef EXCEPTION_H_
48 #define EXCEPTION_H_
49 
50 #include "util.h"
51 
52 namespace mui {
53 
54 inline std::ostream& operator << ( std::ostream &out, std::exception const& err ) {
55  return ( out << err.what() );
56 }
57 
59  explicit inline exception_segv() {
60  handle();
61  }
62  template<typename HEAD, typename ...TAIL>
63  inline exception_segv( HEAD const &head, TAIL const &... tail ) {
64  handle( head, tail... );
65  }
66  template<typename HEAD, typename ...TAIL>
67  inline void handle( HEAD const &head, TAIL const &... tail ) {
68  std::cerr << head;
69  handle( tail... );
70  }
71  inline void handle( void ) {
72  raise( SIGSEGV );
73  }
74 };
75 
77  inline exception_abort( const std::exception& except ) {
78  std::cerr << except.what() << std::endl;
79  raise( SIGABRT );
80  }
81 };
82 
84  inline exception_throw( const std::exception& ) {
85  throw;
86  }
87 };
88 
89 }
90 #endif /* EXCEPTION_H_ */
Definition: comm.h:54
ostream & operator<<(ostream &stream, const smalluint &sml)
Definition: comm_tcp.h:127
Definition: exception.h:76
exception_abort(const std::exception &except)
Definition: exception.h:77
Definition: exception.h:58
void handle(HEAD const &head, TAIL const &... tail)
Definition: exception.h:67
void handle(void)
Definition: exception.h:71
exception_segv()
Definition: exception.h:59
exception_segv(HEAD const &head, TAIL const &... tail)
Definition: exception.h:63
Definition: exception.h:83
exception_throw(const std::exception &)
Definition: exception.h:84
Provides a number of utility functions used through the rest of the library.