Quantum++  v1.0-rc2
A modern C++11 quantum computing library
exception.h
Go to the documentation of this file.
1 /*
2  * Quantum++
3  *
4  * Copyright (c) 2013 - 2017 Vlad Gheorghiu (vgheorgh@gmail.com)
5  *
6  * This file is part of Quantum++.
7  *
8  * Quantum++ is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * Quantum++ is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Quantum++. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
27 #ifndef CLASSES_EXCEPTION1_H_
28 #define CLASSES_EXCEPTION1_H_
29 
30 namespace qpp
31 {
36 namespace exception
37 {
68 class Exception : public std::exception
69 {
70 private:
71  std::string where_;
72 public:
78  Exception(const std::string& where) : where_{where}
79  {}
80 
86  virtual const char* what() const noexcept override
87  {
88  std::string msg_;
89  msg_ += "IN ";
90  msg_ += where_;
91  msg_ += ": ";
92  msg_ += this->type_description();
93  msg_ += "!";
94  return msg_.c_str();
95  }
96 
102  virtual std::string type_description() const = 0;
103 }; /* class Exception */
104 
105 inline std::string Exception::type_description() const
106 {
107  return "qpp::exception::Exception";
108 }
109 
117 class Unknown : public Exception
118 {
119 public:
120  std::string type_description() const override
121  {
122  return "UNKNOWN EXCEPTION";
123  }
124 
125  using Exception::Exception;
126 };
127 
134 class ZeroSize : public Exception
135 {
136 public:
137  std::string type_description() const override
138  {
139  return "Object has zero size";
140  }
141 
142  using Exception::Exception;
143 };
144 
152 {
153 public:
154  std::string type_description() const override
155  {
156  return "Matrix is not square";
157  }
158 
159  using Exception::Exception;
160 };
161 
169 {
170 public:
171  std::string type_description() const override
172  {
173  return "Matrix is not a column vector";
174  }
175 
176  using Exception::Exception;
177 };
178 
186 {
187 public:
188  std::string type_description() const override
189  {
190  return "Matrix is not a row vector";
191  }
192 
193  using Exception::Exception;
194 };
195 
203 {
204 public:
205  std::string type_description() const override
206  {
207  return "Matrix is not a vector";
208  }
209 
210  using Exception::Exception;
211 };
212 
220 {
221 public:
222  std::string type_description() const override
223  {
224  return "Matrix is not square nor column vector";
225  }
226 
227  using Exception::Exception;
228 };
229 
237 {
238 public:
239  std::string type_description() const override
240  {
241  return "Matrix is not square nor row vector";
242  }
243 
244  using Exception::Exception;
245 };
246 
254 {
255 public:
256  std::string type_description() const override
257  {
258  return "Matrix is not square nor vector";
259  }
260 
261  using Exception::Exception;
262 };
263 
271 {
272 public:
273  std::string type_description() const override
274  {
275  return "Matrix mismatch subsystems";
276  }
277 
278  using Exception::Exception;
279 };
280 
287 class DimsInvalid : public Exception
288 {
289 public:
290  std::string type_description() const override
291  {
292  return "Invalid dimension(s)";
293  }
294 
295  using Exception::Exception;
296 };
297 
304 class DimsNotEqual : public Exception
305 {
306 public:
307  std::string type_description() const override
308  {
309  return "Dimensions not equal";
310  }
311 
312  using Exception::Exception;
313 };
314 
323 {
324 public:
325  std::string type_description() const override
326  {
327  return "Dimension(s) mismatch matrix size";
328  }
329 
330  using Exception::Exception;
331 };
332 
341 {
342 public:
343  std::string type_description() const override
344  {
345  return "Dimension(s) mismatch column vector size";
346  }
347 
348  using Exception::Exception;
349 };
350 
359 {
360 public:
361  std::string type_description() const override
362  {
363  return "Dimension(s) mismatch row vector size";
364  }
365 
366  using Exception::Exception;
367 };
368 
378 {
379 public:
380  std::string type_description() const override
381  {
382  return "Dimension(s) mismatch vector size";
383  }
384 
385  using Exception::Exception;
386 };
387 
396 {
397 public:
398  std::string type_description() const override
399  {
400  return "Subsystems mismatch dimensions";
401  }
402 
403  using Exception::Exception;
404 };
405 
412 class PermInvalid : public Exception
413 {
414 public:
415  std::string type_description() const override
416  {
417  return "Invalid permutation";
418  }
419 
420  using Exception::Exception;
421 };
422 
431 {
432 public:
433  std::string type_description() const override
434  {
435  return "Permutation mismatch dimensions";
436  }
437 
438  using Exception::Exception;
439 };
440 
447 class NotQubitMatrix : public Exception
448 {
449 public:
450  std::string type_description() const override
451  {
452  return "Matrix is not 2 x 2";
453  }
454 
455  using Exception::Exception;
456 };
457 
465 {
466 public:
467  std::string type_description() const override
468  {
469  return "Column vector is not 2 x 1";
470  }
471 
472  using Exception::Exception;
473 };
474 
482 {
483 public:
484  std::string type_description() const override
485  {
486  return "Row vector is not 1 x 2";
487  }
488 
489  using Exception::Exception;
490 };
491 
498 class NotQubitVector : public Exception
499 {
500 public:
501  std::string type_description() const override
502  {
503  return "Vector is not 2 x 1 nor 1 x 2";
504  }
505 
506  using Exception::Exception;
507 };
508 
515 class NotQubitSubsys : public Exception
516 {
517 public:
518  std::string type_description() const override
519  {
520  return "Subsystems are not qubits";
521  }
522 
523  using Exception::Exception;
524 };
525 
532 class NotBipartite : public Exception
533 {
534 public:
535  std::string type_description() const override
536  {
537  return "Not bi-partite";
538  }
539 
540  using Exception::Exception;
541 };
542 
550 class NoCodeword : public Exception
551 {
552 public:
553  std::string type_description() const override
554  {
555  return "Codeword does not exist";
556  }
557 
558  using Exception::Exception;
559 };
560 
567 class OutOfRange : public Exception
568 {
569 public:
570  std::string type_description() const override
571  {
572  return "Parameter out of range";
573  }
574 
575  using Exception::Exception;
576 };
577 
578 
585 class TypeMismatch : public Exception
586 {
587 public:
588  std::string type_description() const override
589  {
590  return "Type mismatch";
591  }
592 
593  using Exception::Exception;
594 };
595 
602 class SizeMismatch : public Exception
603 {
604 public:
605  std::string type_description() const override
606  {
607  return "Size mismatch";
608  }
609 
610  using Exception::Exception;
611 };
612 
619 class UndefinedType : public Exception
620 {
621 public:
622  std::string type_description() const override
623  {
624  return "Not defined for this type";
625  }
626 
627  using Exception::Exception;
628 };
629 
637 {
638  std::string what_{};
639 
640  std::string type_description() const override
641  {
642  return "CUSTOM EXCEPTION " + what_;
643  }
644 
645 public:
646  CustomException(const std::string& where, const std::string& what) :
647  Exception{where}, what_{what}
648  {}
649 };
650 
651 } /* namespace exceptions */
652 } /* namespace qpp */
653 
654 #endif /* CLASSES_EXCEPTION1_H_ */
Dimensions not equal exception.
Definition: exception.h:304
Dimension(s) mismatch matrix size exception.
Definition: exception.h:322
std::string type_description() const override
Exception type description.
Definition: exception.h:137
Matrix is not a vector exception.
Definition: exception.h:202
Matrix is not square nor vector exception.
Definition: exception.h:253
Not defined for this type exception.
Definition: exception.h:619
Custom exception.
Definition: exception.h:636
std::string type_description() const override
Exception type description.
Definition: exception.h:484
std::string type_description() const override
Exception type description.
Definition: exception.h:343
std::string type_description() const override
Exception type description.
Definition: exception.h:553
std::string type_description() const override
Exception type description.
Definition: exception.h:570
Subsystems mismatch dimensions exception.
Definition: exception.h:395
std::string type_description() const override
Exception type description.
Definition: exception.h:605
std::string type_description() const override
Exception type description.
Definition: exception.h:188
Matrix is not a column vector exception.
Definition: exception.h:168
Quantum++ main namespace.
Definition: codes.h:30
std::string type_description() const override
Exception type description.
Definition: exception.h:398
std::string type_description() const override
Exception type description.
Definition: exception.h:205
std::string where_
Definition: exception.h:71
Matrix is not square nor column vector exception.
Definition: exception.h:219
std::string type_description() const override
Exception type description.
Definition: exception.h:222
Invalid dimension(s) exception.
Definition: exception.h:287
Subsystems are not qubits exception.
Definition: exception.h:515
Not bi-partite exception.
Definition: exception.h:532
Dimension(s) mismatch row vector size exception.
Definition: exception.h:358
std::string type_description() const override
Exception type description.
Definition: exception.h:622
Column vector is not 2 x 1 exception.
Definition: exception.h:464
std::string type_description() const override
Exception type description.
Definition: exception.h:535
Invalid permutation exception.
Definition: exception.h:412
std::string type_description() const override
Exception type description.
Definition: exception.h:307
Exception(const std::string &where)
Constructs an exception.
Definition: exception.h:78
Matrix mismatch subsystems exception.
Definition: exception.h:270
Codeword does not exist exception.
Definition: exception.h:550
Vector is not 2 x 1 nor 1 x 2 exception.
Definition: exception.h:498
std::string type_description() const override
Exception type description.
Definition: exception.h:256
std::string type_description() const override
Exception type description.
Definition: exception.h:501
std::string type_description() const override
Exception type description.
Definition: exception.h:273
std::string type_description() const override
Exception type description.
Definition: exception.h:361
Dimension(s) mismatch column vector size exception.
Definition: exception.h:340
std::string type_description() const override
Exception type description.
Definition: exception.h:518
std::string type_description() const override
Exception type description.
Definition: exception.h:467
Type mismatch exception.
Definition: exception.h:585
std::string type_description() const override
Exception type description.
Definition: exception.h:120
std::string type_description() const override
Exception type description.
Definition: exception.h:450
Matrix is not a row vector exception.
Definition: exception.h:185
Row vector is not 1 x 2 exception.
Definition: exception.h:481
Parameter out of range exception.
Definition: exception.h:567
std::string type_description() const override
Exception type description.
Definition: exception.h:239
CustomException(const std::string &where, const std::string &what)
Definition: exception.h:646
Matrix is not 2 x 2 exception.
Definition: exception.h:447
std::string type_description() const override
Exception type description.
Definition: exception.h:380
Unknown exception.
Definition: exception.h:117
std::string type_description() const override
Exception type description.
Definition: exception.h:588
std::string type_description() const override
Exception type description.
Definition: exception.h:290
Dimension(s) mismatch vector size exception.
Definition: exception.h:377
std::string type_description() const override
Exception type description.
Definition: exception.h:325
Permutation mismatch dimensions exception.
Definition: exception.h:430
virtual const char * what() const noexcept override
Overrides std::exception::what()
Definition: exception.h:86
Size mismatch exception.
Definition: exception.h:602
std::string type_description() const override
Exception type description.
Definition: exception.h:640
Matrix is not square exception.
Definition: exception.h:151
std::string type_description() const override
Exception type description.
Definition: exception.h:171
std::string type_description() const override
Exception type description.
Definition: exception.h:154
std::string type_description() const override
Exception type description.
Definition: exception.h:415
Base class for generating Quantum++ custom exceptions.
Definition: exception.h:68
Matrix is not square nor row vector exception.
Definition: exception.h:236
std::string type_description() const override
Exception type description.
Definition: exception.h:433
virtual std::string type_description() const =0
Exception type description.
Definition: exception.h:105
Object has zero size exception.
Definition: exception.h:134