Quantum++  v1.0-rc3
A modern C++11 quantum computing library
exception.h
Go to the documentation of this file.
1 /*
2  * This file is part of Quantum++.
3  *
4  * MIT License
5  *
6  * Copyright (c) 2013 - 2018 Vlad Gheorghiu (vgheorgh@gmail.com)
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26 
32 #ifndef CLASSES_EXCEPTION1_H_
33 #define CLASSES_EXCEPTION1_H_
34 
35 namespace qpp {
40 namespace exception {
71 class Exception : public std::exception {
72  private:
73  std::string where_;
74 
75  public:
81  Exception(const std::string& where) : where_{where} {}
82 
88  virtual const char* what() const noexcept override {
89  std::string msg_;
90  msg_ += "IN ";
91  msg_ += where_;
92  msg_ += ": ";
93  msg_ += this->type_description();
94  msg_ += "!";
95  return msg_.c_str();
96  }
97 
103  virtual std::string type_description() const = 0;
104 }; /* class Exception */
105 
106 inline std::string Exception::type_description() const {
107  return "qpp::exception::Exception";
108 }
109 
117 class Unknown : public Exception {
118  public:
119  std::string type_description() const override {
120  return "UNKNOWN EXCEPTION";
121  }
122 
123  using Exception::Exception;
124 };
125 
132 class ZeroSize : public Exception {
133  public:
134  std::string type_description() const override {
135  return "Object has zero size";
136  }
137 
138  using Exception::Exception;
139 };
140 
147 class MatrixNotSquare : public Exception {
148  public:
149  std::string type_description() const override {
150  return "Matrix is not square";
151  }
152 
153  using Exception::Exception;
154 };
155 
162 class MatrixNotCvector : public Exception {
163  public:
164  std::string type_description() const override {
165  return "Matrix is not a column vector";
166  }
167 
168  using Exception::Exception;
169 };
170 
177 class MatrixNotRvector : public Exception {
178  public:
179  std::string type_description() const override {
180  return "Matrix is not a row vector";
181  }
182 
183  using Exception::Exception;
184 };
185 
192 class MatrixNotVector : public Exception {
193  public:
194  std::string type_description() const override {
195  return "Matrix is not a vector";
196  }
197 
198  using Exception::Exception;
199 };
200 
208  public:
209  std::string type_description() const override {
210  return "Matrix is not square nor column vector";
211  }
212 
213  using Exception::Exception;
214 };
215 
223  public:
224  std::string type_description() const override {
225  return "Matrix is not square nor row vector";
226  }
227 
228  using Exception::Exception;
229 };
230 
238  public:
239  std::string type_description() const override {
240  return "Matrix is not square nor vector";
241  }
242 
243  using Exception::Exception;
244 };
245 
253  public:
254  std::string type_description() const override {
255  return "Matrix mismatch subsystems";
256  }
257 
258  using Exception::Exception;
259 };
260 
267 class DimsInvalid : public Exception {
268  public:
269  std::string type_description() const override {
270  return "Invalid dimension(s)";
271  }
272 
273  using Exception::Exception;
274 };
275 
282 class DimsNotEqual : public Exception {
283  public:
284  std::string type_description() const override {
285  return "Dimensions not equal";
286  }
287 
288  using Exception::Exception;
289 };
290 
299  public:
300  std::string type_description() const override {
301  return "Dimension(s) mismatch matrix size";
302  }
303 
304  using Exception::Exception;
305 };
306 
315  public:
316  std::string type_description() const override {
317  return "Dimension(s) mismatch column vector size";
318  }
319 
320  using Exception::Exception;
321 };
322 
331  public:
332  std::string type_description() const override {
333  return "Dimension(s) mismatch row vector size";
334  }
335 
336  using Exception::Exception;
337 };
338 
348  public:
349  std::string type_description() const override {
350  return "Dimension(s) mismatch vector size";
351  }
352 
353  using Exception::Exception;
354 };
355 
364  public:
365  std::string type_description() const override {
366  return "Subsystems mismatch dimensions";
367  }
368 
369  using Exception::Exception;
370 };
371 
378 class PermInvalid : public Exception {
379  public:
380  std::string type_description() const override {
381  return "Invalid permutation";
382  }
383 
384  using Exception::Exception;
385 };
386 
394 class PermMismatchDims : public Exception {
395  public:
396  std::string type_description() const override {
397  return "Permutation mismatch dimensions";
398  }
399 
400  using Exception::Exception;
401 };
402 
409 class NotQubitMatrix : public Exception {
410  public:
411  std::string type_description() const override {
412  return "Matrix is not 2 x 2";
413  }
414 
415  using Exception::Exception;
416 };
417 
424 class NotQubitCvector : public Exception {
425  public:
426  std::string type_description() const override {
427  return "Column vector is not 2 x 1";
428  }
429 
430  using Exception::Exception;
431 };
432 
439 class NotQubitRvector : public Exception {
440  public:
441  std::string type_description() const override {
442  return "Row vector is not 1 x 2";
443  }
444 
445  using Exception::Exception;
446 };
447 
454 class NotQubitVector : public Exception {
455  public:
456  std::string type_description() const override {
457  return "Vector is not 2 x 1 nor 1 x 2";
458  }
459 
460  using Exception::Exception;
461 };
462 
469 class NotQubitSubsys : public Exception {
470  public:
471  std::string type_description() const override {
472  return "Subsystems are not qubits";
473  }
474 
475  using Exception::Exception;
476 };
477 
484 class NotBipartite : public Exception {
485  public:
486  std::string type_description() const override { return "Not bi-partite"; }
487 
488  using Exception::Exception;
489 };
490 
498 class NoCodeword : public Exception {
499  public:
500  std::string type_description() const override {
501  return "Codeword does not exist";
502  }
503 
504  using Exception::Exception;
505 };
506 
513 class OutOfRange : public Exception {
514  public:
515  std::string type_description() const override {
516  return "Parameter out of range";
517  }
518 
519  using Exception::Exception;
520 };
521 
528 class TypeMismatch : public Exception {
529  public:
530  std::string type_description() const override { return "Type mismatch"; }
531 
532  using Exception::Exception;
533 };
534 
541 class SizeMismatch : public Exception {
542  public:
543  std::string type_description() const override { return "Size mismatch"; }
544 
545  using Exception::Exception;
546 };
547 
554 class UndefinedType : public Exception {
555  public:
556  std::string type_description() const override {
557  return "Not defined for this type";
558  }
559 
560  using Exception::Exception;
561 };
562 
569 class CustomException : public Exception {
570  std::string what_{};
571 
572  std::string type_description() const override {
573  return "CUSTOM EXCEPTION " + what_;
574  }
575 
576  public:
577  CustomException(const std::string& where, const std::string& what)
578  : Exception{where}, what_{what} {}
579 };
580 
581 } /* namespace exceptions */
582 } /* namespace qpp */
583 
584 #endif /* CLASSES_EXCEPTION1_H_ */
Dimensions not equal exception.
Definition: exception.h:282
Dimension(s) mismatch matrix size exception.
Definition: exception.h:298
std::string type_description() const override
Exception type description.
Definition: exception.h:134
Matrix is not a vector exception.
Definition: exception.h:192
Matrix is not square nor vector exception.
Definition: exception.h:237
Not defined for this type exception.
Definition: exception.h:554
Custom exception.
Definition: exception.h:569
std::string type_description() const override
Exception type description.
Definition: exception.h:441
std::string type_description() const override
Exception type description.
Definition: exception.h:316
std::string type_description() const override
Exception type description.
Definition: exception.h:500
std::string type_description() const override
Exception type description.
Definition: exception.h:515
Subsystems mismatch dimensions exception.
Definition: exception.h:363
std::string type_description() const override
Exception type description.
Definition: exception.h:543
std::string type_description() const override
Exception type description.
Definition: exception.h:179
Matrix is not a column vector exception.
Definition: exception.h:162
Quantum++ main namespace.
Definition: codes.h:35
std::string type_description() const override
Exception type description.
Definition: exception.h:365
std::string type_description() const override
Exception type description.
Definition: exception.h:194
std::string where_
Definition: exception.h:73
Matrix is not square nor column vector exception.
Definition: exception.h:207
std::string type_description() const override
Exception type description.
Definition: exception.h:209
Invalid dimension(s) exception.
Definition: exception.h:267
Subsystems are not qubits exception.
Definition: exception.h:469
Not bi-partite exception.
Definition: exception.h:484
Dimension(s) mismatch row vector size exception.
Definition: exception.h:330
std::string type_description() const override
Exception type description.
Definition: exception.h:556
Column vector is not 2 x 1 exception.
Definition: exception.h:424
std::string type_description() const override
Exception type description.
Definition: exception.h:486
Invalid permutation exception.
Definition: exception.h:378
std::string type_description() const override
Exception type description.
Definition: exception.h:284
Exception(const std::string &where)
Constructs an exception.
Definition: exception.h:81
Matrix mismatch subsystems exception.
Definition: exception.h:252
Codeword does not exist exception.
Definition: exception.h:498
Vector is not 2 x 1 nor 1 x 2 exception.
Definition: exception.h:454
std::string type_description() const override
Exception type description.
Definition: exception.h:239
std::string type_description() const override
Exception type description.
Definition: exception.h:456
std::string type_description() const override
Exception type description.
Definition: exception.h:254
std::string type_description() const override
Exception type description.
Definition: exception.h:332
Dimension(s) mismatch column vector size exception.
Definition: exception.h:314
std::string type_description() const override
Exception type description.
Definition: exception.h:471
std::string type_description() const override
Exception type description.
Definition: exception.h:426
Type mismatch exception.
Definition: exception.h:528
std::string type_description() const override
Exception type description.
Definition: exception.h:119
std::string type_description() const override
Exception type description.
Definition: exception.h:411
Matrix is not a row vector exception.
Definition: exception.h:177
Row vector is not 1 x 2 exception.
Definition: exception.h:439
Parameter out of range exception.
Definition: exception.h:513
std::string type_description() const override
Exception type description.
Definition: exception.h:224
CustomException(const std::string &where, const std::string &what)
Definition: exception.h:577
Matrix is not 2 x 2 exception.
Definition: exception.h:409
std::string type_description() const override
Exception type description.
Definition: exception.h:349
Unknown exception.
Definition: exception.h:117
std::string type_description() const override
Exception type description.
Definition: exception.h:530
std::string type_description() const override
Exception type description.
Definition: exception.h:269
Dimension(s) mismatch vector size exception.
Definition: exception.h:347
std::string type_description() const override
Exception type description.
Definition: exception.h:300
Permutation mismatch dimensions exception.
Definition: exception.h:394
virtual const char * what() const noexcept override
Overrides std::exception::what()
Definition: exception.h:88
Size mismatch exception.
Definition: exception.h:541
std::string type_description() const override
Exception type description.
Definition: exception.h:572
Matrix is not square exception.
Definition: exception.h:147
std::string type_description() const override
Exception type description.
Definition: exception.h:164
std::string type_description() const override
Exception type description.
Definition: exception.h:149
std::string type_description() const override
Exception type description.
Definition: exception.h:380
Base class for generating Quantum++ custom exceptions.
Definition: exception.h:71
Matrix is not square nor row vector exception.
Definition: exception.h:222
std::string type_description() const override
Exception type description.
Definition: exception.h:396
virtual std::string type_description() const =0
Exception type description.
Definition: exception.h:106
Object has zero size exception.
Definition: exception.h:132