1 : /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 2002
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Peter Van der Beken <peterv@netscape.com> (original author)
24 : *
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef nsIBaseDOMException_h___
41 : #define nsIBaseDOMException_h___
42 :
43 : #include "nsIDOMClassInfo.h"
44 :
45 : // {1f13b201-39fa-11d6-a7f2-df501ff820dc}
46 : #define NS_BASE_DOM_EXCEPTION_CID \
47 : { 0x1f13b201, 0x39fa, 0x11d6, \
48 : { 0xa7, 0xf2, 0xdf, 0x50, 0x1f, 0xf8, 0x20, 0xdc } }
49 :
50 : // {731d9701-39f8-11d6-a7f2-b39073384c9c}
51 : #define NS_IBASEDOMEXCEPTION_IID \
52 : { 0x731d9701, 0x39f8, 0x11d6, \
53 : { 0xa7, 0xf2, 0xb3, 0x90, 0x73, 0x38, 0x4c, 0x9c } }
54 :
55 207 : class nsIBaseDOMException : public nsISupports {
56 : public:
57 : NS_DECLARE_STATIC_IID_ACCESSOR(NS_IBASEDOMEXCEPTION_IID)
58 :
59 : NS_IMETHOD Init(nsresult aNSResult, const char* aName,
60 : const char* aMessage,
61 : nsIException* aDefaultException) = 0;
62 : };
63 :
64 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIBaseDOMException, NS_IBASEDOMEXCEPTION_IID)
65 :
66 : #define IMPL_DOM_EXCEPTION_HEAD(classname, ifname) \
67 : class classname : public nsIException, \
68 : public ifname \
69 : { \
70 : public: \
71 : classname(nsIException* aInner); \
72 : virtual ~classname(); \
73 : \
74 : NS_DECL_ISUPPORTS \
75 : NS_FORWARD_NSIEXCEPTION(mBase->)
76 :
77 : // Note: the exception implemented by this macro doesn't free the pointers
78 : // it gets from the mapping_function and assumes they will be valid
79 : // as long as the exception object is alive.
80 :
81 : #define IMPL_DOM_EXCEPTION_TAIL(classname, ifname, domname, module, \
82 : mapping_function) \
83 : private: \
84 : nsCOMPtr<nsIException> mBase; \
85 : }; \
86 : \
87 : classname::classname(nsIException* aInner) : mBase(aInner) \
88 : { \
89 : } \
90 : classname::~classname() {} \
91 : \
92 : NS_IMPL_ADDREF(classname) \
93 : NS_IMPL_RELEASE(classname) \
94 : NS_INTERFACE_MAP_BEGIN(classname) \
95 : NS_INTERFACE_MAP_ENTRY(nsIException) \
96 : NS_INTERFACE_MAP_ENTRY(ifname) \
97 : NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIException) \
98 : NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(domname) \
99 : NS_INTERFACE_MAP_END \
100 : \
101 : NS_DEFINE_CID(kBaseDOMException_CID_##domname, NS_BASE_DOM_EXCEPTION_CID); \
102 : \
103 : nsresult \
104 : NS_New##domname(nsresult aNSResult, nsIException* aDefaultException, \
105 : nsIException** aException) \
106 : { \
107 : if (!(NS_ERROR_GET_MODULE(aNSResult) == module)) { \
108 : NS_WARNING("Trying to create an exception for the wrong error module."); \
109 : return NS_ERROR_FAILURE; \
110 : } \
111 : const char* name; \
112 : const char* message; \
113 : mapping_function(aNSResult, &name, &message); \
114 : nsCOMPtr<nsIBaseDOMException> baseException = \
115 : do_CreateInstance(kBaseDOMException_CID_##domname); \
116 : NS_ENSURE_TRUE(baseException, NS_ERROR_OUT_OF_MEMORY); \
117 : baseException->Init(aNSResult, name, message, aDefaultException); \
118 : nsCOMPtr<nsIException> inner = do_QueryInterface(baseException); \
119 : *aException = new classname(inner); \
120 : NS_ENSURE_TRUE(*aException, NS_ERROR_OUT_OF_MEMORY); \
121 : NS_ADDREF(*aException); \
122 : return NS_OK; \
123 : }
124 :
125 : #endif /* nsIBaseDOMException_h___ */
|