All Classes Namespaces Files Functions Variables Pages
exceptions.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2016 DNAnexus, Inc.
2 //
3 // This file is part of dx-toolkit (DNAnexus platform client libraries).
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License"); you may
6 // not use this file except in compliance with the License. You may obtain a
7 // copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 // License for the specific language governing permissions and limitations
15 // under the License.
16 
22 #ifndef DXCPP_EXCEPTIONS_H
23 #define DXCPP_EXCEPTIONS_H
24 
25 #include <exception>
26 #include <string>
27 #include <boost/lexical_cast.hpp>
28 
29 namespace dx {
33  namespace DXErrorTypes {
34  static const std::string DEFAULT_ERROR = "DXDefaultError";
35  static const std::string DXFILE_ERROR = "DXFileError";
36  static const std::string DXAPP_ERROR = "DXAppError";
37  static const std::string DXJOB_ERROR = "DXJobError";
38  static const std::string DXCONNECTION_ERROR = "DXConnectionError";
39  static const std::string DXNOT_IMPLEMENTED_ERROR = "DXNotImplementedError";
40  }
41 
43  class DXError: public std::exception {
44  public:
45  std::string msg;
46  std::string type;
47  mutable std::string error_msg; // store the error message generated by what()
48 
49  DXError(): msg("Unknown error occured while using dxcpp.") { }
50  DXError(const std::string &msg, const std::string &type = DXErrorTypes::DEFAULT_ERROR): msg(msg), type(type) { }
51  virtual const char* what() const throw() {
52  error_msg = type + ": '" + msg + "'";
53  return (const char*)msg.c_str();
54  }
55 
56  virtual ~DXError() throw() { }
57 
58  };
59 
64  class DXAPIError: public DXError {
65  public:
66  int resp_code;
67 
68  DXAPIError(std::string msg, std::string type, int resp_code) :
69  DXError(msg, type), resp_code(resp_code) {}
70 
71  virtual const char* what() const throw() {
72  error_msg = type + ": '" + msg + "', Server returned HTTP code '" + boost::lexical_cast<std::string>(resp_code) + "'";
73  return (const char*)error_msg.c_str();
74  }
75 
76  virtual ~DXAPIError() throw() { }
77  };
78 
79  class DXConnectionError: public DXError {
80  public:
81  int curl_code;
82 
83  DXConnectionError(const std::string msg, int curl_code, const std::string &type=DXErrorTypes::DXCONNECTION_ERROR):
84  DXError(msg, type), curl_code(curl_code) {}
85 
86  virtual const char* what() const throw() {
87  error_msg = type + ": '" + msg + "', Curl error code = '" + boost::lexical_cast<std::string>(curl_code) + "'";
88  return (const char*)error_msg.c_str();
89  }
90 
91  virtual ~DXConnectionError() throw() { }
92  };
93 
95  class DXFileError: public DXError {
96  public:
97  DXFileError(): DXError("Unknown error occured while using DXFile class.") { }
98  DXFileError(const std::string &msg, const std::string &type=DXErrorTypes::DXFILE_ERROR): DXError(msg, type) { }
99 
100  virtual ~DXFileError() throw() { }
101  };
102 
104  class DXAppError: public DXError {
105  public:
106  DXAppError(): DXError("Unknown error occured while using DXApp class.") { }
107  DXAppError(const std::string &msg, const std::string &type=DXErrorTypes::DXAPP_ERROR): DXError(msg, type) { }
108 
109  virtual ~DXAppError() throw() { }
110  };
111 
113  class DXJobError: public DXError {
114  public:
115  DXJobError(): DXError("Unknown error occured while using DXJob class.") { }
116  DXJobError(const std::string &msg, const std::string &type=DXErrorTypes::DXJOB_ERROR): DXError(msg, type) { }
117 
118  virtual ~DXJobError() throw() { }
119  };
120 
126  public:
127  DXNotImplementedError(): DXError("Not yet implemented.") { }
128  DXNotImplementedError(const std::string &msg, const std::string &type=DXErrorTypes::DXNOT_IMPLEMENTED_ERROR): DXError(msg, type) { }
129 
130  virtual ~DXNotImplementedError() throw() { }
131  };
132 }
133 
134 #endif
Represents errors relating to the DXJob class.
Definition: exceptions.h:113
std::string msg
The actual error message.
Definition: exceptions.h:45
int curl_code
Curl code (returned by libcurl)
Definition: exceptions.h:81
Definition: exceptions.h:125
Represents errors relating to the DXApp class.
Definition: exceptions.h:104
Definition: exceptions.h:64
Generic exception for the DNAnexus C++ library.
Definition: exceptions.h:43
std::string type
Type of the error message (can be a free-form string, but usually one of the static members from DXEr...
Definition: exceptions.h:46
Represents errors relating to the DXFile class.
Definition: exceptions.h:95
int resp_code
HTTP status code returned by the apiserver.
Definition: exceptions.h:66
Definition: exceptions.h:79