1 /* $Id: seqalign_exception.hpp 574980 2018-11-21 14:24:48Z ucko $
2  * ===========================================================================
3  *
4  *                            PUBLIC DOMAIN NOTICE
5  *               National Center for Biotechnology Information
6  *
7  *  This software/database is a "United States Government Work" under the
8  *  terms of the United States Copyright Act.  It was written as part of
9  *  the author's official duties as a United States Government employee and
10  *  thus cannot be copyrighted.  This software/database is freely available
11  *  to the public for use. The National Library of Medicine and the U.S.
12  *  Government have not placed any restriction on its use or reproduction.
13  *
14  *  Although all reasonable efforts have been taken to ensure the accuracy
15  *  and reliability of the software and data, the NLM and the U.S.
16  *  Government do not and cannot warrant the performance or results that
17  *  may be obtained by using this software or data. The NLM and the U.S.
18  *  Government disclaim all warranties, express or implied, including
19  *  warranties of performance, merchantability or fitness for any particular
20  *  purpose.
21  *
22  *  Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Philip Johnson
27  *
28  * File Description: CSeqalignException class
29  *
30  */
31 
32 #ifndef OBJECTS_SEQALIGN_SEQALIGN_EXCEPTION_HPP
33 #define OBJECTS_SEQALIGN_SEQALIGN_EXCEPTION_HPP
34 
35 #include <corelib/ncbiexpt.hpp>
36 
37 BEGIN_NCBI_SCOPE
38 BEGIN_SCOPE(objects) // namespace ncbi::objects::
39 
40 class CSeqalignException : EXCEPTION_VIRTUAL_BASE public CException
41 {
42 public:
43     enum EErrCode {
44         /// Operation that is undefined for the given input Seq-align,
45         /// and which is impossible to perform.
46         eUnsupported,
47 
48         /// The current alignment has a structural or data error.
49         ///
50         /// This error code applies to problems on "this" object
51         /// in member functions of an alignment object. Note that
52         /// mismatches between alignment types and scores that
53         /// are not supported for them are indicated by eUnsupported.
54         eInvalidAlignment,
55 
56         /// An invalid alignmnent passed as input to the current
57         /// operation has a structural or data error.
58         ///
59         /// This error code applies to problems on an alignment
60         /// object other than "this" object. Note that
61         /// mismatches between alignment types and scores that
62         /// are not supported for them are indicated by eUnsupported.
63         eInvalidInputAlignment,
64 
65         eInvalidRowNumber,
66         eOutOfRange,
67         eInvalidInputData,
68 
69         /// A sequence identifier is invalid or cannot be
70         /// resolved within the relevant scope.
71         eInvalidSeqId,
72 
73         /// Attempt to use unimplemented funtionality.
74         ///
75         /// The operation could be performed, in theory, but
76         /// current code is incomplete and requires modification
77         /// to provided the desired functionality.
78         eNotImplemented
79     };
80 
GetErrCodeString(void) const81     virtual const char* GetErrCodeString(void) const override
82     {
83         switch (GetErrCode()) {
84         case eUnsupported:           return "eUnsupported";
85         case eInvalidAlignment:      return "eInvalidAlignment";
86         case eInvalidInputAlignment: return "eInvalidInputAlignment";
87         case eInvalidRowNumber:      return "eInvalidRowNumber";
88         case eOutOfRange:            return "eOutOfRange";
89         case eInvalidInputData:      return "eInvalidInputData";
90         case eInvalidSeqId:          return "eInvalidSeqId";
91         case eNotImplemented:        return "eNotImplemented";
92         default:                     return CException::GetErrCodeString();
93         }
94     }
95 
96     NCBI_EXCEPTION_DEFAULT(CSeqalignException, CException);
97 };
98 
99 #define _SEQALIGN_ASSERT(expr) \
100     do {                                                               \
101         if ( !(expr) ) {                                               \
102             _ASSERT(expr);                                             \
103             NCBI_THROW(CSeqalignException, eInvalidAlignment,          \
104                        string("Assertion failed: ") + #expr);          \
105         }                                                              \
106     } while ( 0 )
107 
108 END_SCOPE(objects)
109 END_NCBI_SCOPE
110 
111 #endif // OBJECTS_SEQALIGN_SEQALIGN_EXCEPTION_HPP
112