diff --git a/src/error.cpp b/src/error.cpp index 237984bfaf714ea4e279afa28dcb42d7699d80f5..5c24d94832d56a7ecf3d7ca040bc8b46572b88ea 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -22,7 +22,12 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -Error::Error(LAMMPS *lmp) : Pointers(lmp), last_error_message(NULL), last_error_type(ERROR_NONE) {} +Error::Error(LAMMPS *lmp) : Pointers(lmp) { +#ifdef LAMMPS_EXCEPTIONS + last_error_message = NULL; + last_error_type = ERROR_NONE; +#endif +} /* ---------------------------------------------------------------------- called by all procs in universe @@ -198,6 +203,7 @@ void Error::done(int status) exit(status); } +#ifdef LAMMPS_EXCEPTIONS /* ---------------------------------------------------------------------- return the last error message reported by LAMMPS (only used if compiled with -DLAMMPS_EXCEPTIONS) @@ -235,3 +241,4 @@ void Error::set_last_error(const char * msg, ErrorType type) } last_error_type = type; } +#endif diff --git a/src/error.h b/src/error.h index 0fa3475d1ed5cf0c0b7b76007c0921a99cb4338a..b66fe4a13b6b3bf48b84bf1065b32027478d8caa 100644 --- a/src/error.h +++ b/src/error.h @@ -15,48 +15,14 @@ #define LMP_ERROR_H #include "pointers.h" -#include <string> -#include <exception> -namespace LAMMPS_NS { - -class LAMMPSException : public std::exception -{ -public: - std::string message; - - LAMMPSException(std::string msg) : message(msg) { - } - - ~LAMMPSException() throw() { - } - - virtual const char * what() const throw() { - return message.c_str(); - } -}; - -class LAMMPSAbortException : public LAMMPSException { -public: - MPI_Comm universe; - - LAMMPSAbortException(std::string msg, MPI_Comm universe) : - LAMMPSException(msg), - universe(universe) - { - } -}; +#ifdef LAMMPS_EXCEPTIONS +#include "exceptions.h" +#endif -enum ErrorType { - ERROR_NONE = 0, - ERROR_NORMAL = 1, - ERROR_ABORT = 2 -}; +namespace LAMMPS_NS { class Error : protected Pointers { - char * last_error_message; - ErrorType last_error_type; - public: Error(class LAMMPS *); @@ -70,9 +36,15 @@ class Error : protected Pointers { void message(const char *, int, const char *, int = 1); void done(int = 0); // 1 would be fully backwards compatible +#ifdef LAMMPS_EXCEPTIONS char * get_last_error() const; ErrorType get_last_error_type() const; void set_last_error(const char * msg, ErrorType type = ERROR_NORMAL); + + private: + char * last_error_message; + ErrorType last_error_type; +#endif }; } diff --git a/src/exceptions.h b/src/exceptions.h new file mode 100644 index 0000000000000000000000000000000000000000..121991afc5422ddb180141669f7b766ed4d8c116 --- /dev/null +++ b/src/exceptions.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- ---------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#ifndef LMP_EXCEPTIONS_H +#define LMP_EXCEPTIONS_H + +#include <mpi.h> +#include <string> +#include <exception> + +namespace LAMMPS_NS { + +class LAMMPSException : public std::exception +{ +public: + std::string message; + + LAMMPSException(std::string msg) : message(msg) { + } + + ~LAMMPSException() throw() { + } + + virtual const char * what() const throw() { + return message.c_str(); + } +}; + +class LAMMPSAbortException : public LAMMPSException { +public: + MPI_Comm universe; + + LAMMPSAbortException(std::string msg, MPI_Comm universe) : + LAMMPSException(msg), + universe(universe) + { + } +}; + +enum ErrorType { + ERROR_NONE = 0, + ERROR_NORMAL = 1, + ERROR_ABORT = 2 +}; + +} + +#endif diff --git a/src/library.cpp b/src/library.cpp index 4d493c979b32deff7c1e6572853602443e6894c7..ae00f106d11e83adde19609fd9f7e796513a7fab 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -109,6 +109,8 @@ void lammps_file(void *ptr, char *str) char *lammps_command(void *ptr, char *str) { LAMMPS * lmp = (LAMMPS *) ptr; + +#ifdef LAMMPS_EXCEPTIONS Error * error = lmp->error; try { @@ -127,6 +129,9 @@ char *lammps_command(void *ptr, char *str) error->set_last_error(e.message.c_str(), ERROR_NORMAL); return NULL; } +#else + return lmp->input->one(str); +#endif } /* ---------------------------------------------------------------------- @@ -611,6 +616,7 @@ void lammps_scatter_atoms(void *ptr, char *name, } } +#ifdef LAMMPS_EXCEPTIONS /* ---------------------------------------------------------------------- Check if a new error message ------------------------------------------------------------------------- */ @@ -640,3 +646,4 @@ int lammps_get_last_error_message(void *ptr, char * buffer, int buffer_size) { } return 0; } +#endif diff --git a/src/library.h b/src/library.h index 5cb128fdb99b0b769792387e76ee031de6ccb437..43e10d8c758ab677b8f0b218fd302c321505217b 100644 --- a/src/library.h +++ b/src/library.h @@ -45,8 +45,10 @@ int lammps_get_natoms(void *); void lammps_gather_atoms(void *, char *, int, int, void *); void lammps_scatter_atoms(void *, char *, int, int, void *); +#ifdef LAMMPS_EXCEPTION int lammps_has_error(void *); int lammps_get_last_error_message(void *, char *, int); +#endif #ifdef __cplusplus }