xref: /aoo42x/main/sw/source/core/except/errhdl.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #ifdef DBG_UTIL
28 
29 #define _ERRHDL_CXX
30 
31 
32 #include "stdlib.h"
33 #include <tools/debug.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/sound.hxx>
36 #include <errhdl.hxx>
37 #include <error.h>				// fuer die defines von ERR_SW6MSG_ ...
38 
39 #ifndef CVBREAK
40 #define CVBREAK
41 #endif
42 
43 sal_Bool bAssertFail = sal_False;			// ist gerade eine Assertbox oben ?
44 sal_Bool bAssert = sal_False;				// sal_True, wenn mal ein ASSERT kam.
45 
46 /*------------------------------------------------------------------------
47 	Ausgabe einer Fehlermeldung inkl. Bedingung, Dateiname und Zeilennummer
48 	wo der Fehler auftrat.
49 	Die Funktion wird durch das ASSERT Makro gerufen!
50 	Parameter:
51 				char	*pError		Fehlermeldung
52 				char	*pFileName	Filename in dem der Fehler auftrat
53 				sal_uInt16	nLine		Zeilennummer in dem der Fehler auftrat
54 ------------------------------------------------------------------------*/
55 
AssertFail(const sal_Char * pError,const sal_Char * pFileName,sal_uInt16 nLine)56 void AssertFail( const sal_Char* pError, const sal_Char* pFileName, sal_uInt16 nLine )
57 {
58 	CVBREAK;
59 	// NOTE4("ASSERT: %s at %d: %s\n", pFileName, nLine, pError);
60 	bAssert = sal_True;
61 
62 	if( !bAssertFail && GetpApp() && GetpApp()->IsInMain() )
63 	{
64 		bAssertFail = sal_True;
65 		ByteString	aErr;
66 		aErr = "Assertion failed\n==================\nFILE      :  ";
67 		aErr += pFileName;
68 		aErr += " at line ";
69 		aErr += ByteString::CreateFromInt32( nLine );
70 		aErr += "\nERROR :  ";
71 		aErr += pError;
72 
73 		ByteString aTmp( getenv( "SW_NOBEEP" ) );
74 		if ( aTmp != "sal_True" )
75 			Sound::Beep(SOUND_ERROR);
76 
77 #if defined( UNX ) && !defined( DBG_UTIL )
78 		DBG_ERROR( aErr.GetBuffer() ); // DbgErr ist in UNIX-nicht Produkt-Versionen nicht definiert
79 #else
80 		DbgError( aErr.GetBuffer() );
81 #endif
82 		bAssertFail = sal_False;
83 	}
84 	else
85 	{
86 		Sound::Beep(SOUND_ERROR);
87 		Sound::Beep(SOUND_ERROR);
88 		Sound::Beep(SOUND_ERROR);
89 		if( !bAssertFail )
90 			*(short *)0 = 4711; 		// UAE ausloesen
91 	}
92 }
93 
94 /*------------------------------------------------------------------------
95 	Ausgabe einer Fehlermeldung inkl. Bedingung, Dateiname und Zeilennummer
96 	wo der Fehler auftrat.
97 	Die Funktion wird durch das ASSERT Makro gerufen!
98 	Parameter:
99 				sal_uInt16	nErrorId	Id fuer Fehlermeldung
100 				char	*pFileName	Filename in dem der Fehler auftrat
101 				sal_uInt16	nLine		Zeilennummer in dem der Fehler auftrat
102 ------------------------------------------------------------------------*/
103 
AssertFail(sal_uInt16 nErrorId,const sal_Char * pFileName,sal_uInt16 nLine)104 void AssertFail( sal_uInt16 nErrorId, const sal_Char* pFileName, sal_uInt16 nLine )
105 {
106 	// Umsetzung der ErrorId in eine Fehlermeldung
107 	static const sal_Char
108 		/* Error Fehlermeldungen zugriffe ausserhalb eines Bereiches */
109 		sERR_VAR_IDX[]		= "Op[]",
110 		sERR_OUTOFSCOPE[]	= "Zugriff ausserhalb des Bereiches",
111 		/* Error Codes fuer Numerierungsregeln */
112 		sERR_NUMLEVEL[] 	= "Falscher Num-Level",
113 		/* Error Codes fuer TxtNode */
114 		sERR_NOHINTS[]		= "Zugriff auf ungueltiges HintsArray",
115 		sERR_UNKNOWN[]		= "???";
116 
117 	static const sal_Char* aErrStrTab[ ERR_SWGMSG_END - ERR_SWGMSG_START +1 ] =
118 	{
119 		sERR_VAR_IDX, sERR_OUTOFSCOPE, sERR_NUMLEVEL, sERR_NOHINTS
120 	};
121 
122 	const sal_Char* pMsg;
123 	if( nErrorId >= ERR_SWGMSG_START && nErrorId < ERR_SWGMSG_END )
124 		pMsg = aErrStrTab[ nErrorId - ERR_SWGMSG_START ];
125 	else
126 		pMsg = sERR_UNKNOWN;
127 
128 	AssertFail( pMsg, pFileName, nLine );
129 }
130 
131 #endif // DBG_UTIL
132 
133