xref: /aoo42x/main/sw/source/core/except/errhdl.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #ifdef DBG_UTIL
32 
33 #define _ERRHDL_CXX
34 
35 
36 #include "stdlib.h"
37 #include <tools/debug.hxx>
38 #include <vcl/svapp.hxx>
39 #include <vcl/sound.hxx>
40 #include <errhdl.hxx>
41 #include <error.h>				// fuer die defines von ERR_SW6MSG_ ...
42 
43 #ifndef CVBREAK
44 #define CVBREAK
45 #endif
46 
47 sal_Bool bAssertFail = sal_False;			// ist gerade eine Assertbox oben ?
48 sal_Bool bAssert = sal_False;				// sal_True, wenn mal ein ASSERT kam.
49 
50 /*------------------------------------------------------------------------
51 	Ausgabe einer Fehlermeldung inkl. Bedingung, Dateiname und Zeilennummer
52 	wo der Fehler auftrat.
53 	Die Funktion wird durch das ASSERT Makro gerufen!
54 	Parameter:
55 				char	*pError		Fehlermeldung
56 				char	*pFileName	Filename in dem der Fehler auftrat
57 				sal_uInt16	nLine		Zeilennummer in dem der Fehler auftrat
58 ------------------------------------------------------------------------*/
59 
60 void AssertFail( const sal_Char* pError, const sal_Char* pFileName, sal_uInt16 nLine )
61 {
62 	CVBREAK;
63 	// NOTE4("ASSERT: %s at %d: %s\n", pFileName, nLine, pError);
64 	bAssert = sal_True;
65 
66 	if( !bAssertFail && GetpApp() && GetpApp()->IsInMain() )
67 	{
68 		bAssertFail = sal_True;
69 		ByteString	aErr;
70 		aErr = "Assertion failed\n==================\nFILE      :  ";
71 		aErr += pFileName;
72 		aErr += " at line ";
73 		aErr += ByteString::CreateFromInt32( nLine );
74 		aErr += "\nERROR :  ";
75 		aErr += pError;
76 
77 		ByteString aTmp( getenv( "SW_NOBEEP" ) );
78 		if ( aTmp != "sal_True" )
79 			Sound::Beep(SOUND_ERROR);
80 
81 #if defined( UNX ) && !defined( DBG_UTIL )
82 		DBG_ERROR( aErr.GetBuffer() ); // DbgErr ist in UNIX-nicht Produkt-Versionen nicht definiert
83 #else
84 		DbgError( aErr.GetBuffer() );
85 #endif
86 		bAssertFail = sal_False;
87 	}
88 	else
89 	{
90 		Sound::Beep(SOUND_ERROR);
91 		Sound::Beep(SOUND_ERROR);
92 		Sound::Beep(SOUND_ERROR);
93 		if( !bAssertFail )
94 			*(short *)0 = 4711; 		// UAE ausloesen
95 	}
96 }
97 
98 /*------------------------------------------------------------------------
99 	Ausgabe einer Fehlermeldung inkl. Bedingung, Dateiname und Zeilennummer
100 	wo der Fehler auftrat.
101 	Die Funktion wird durch das ASSERT Makro gerufen!
102 	Parameter:
103 				sal_uInt16	nErrorId	Id fuer Fehlermeldung
104 				char	*pFileName	Filename in dem der Fehler auftrat
105 				sal_uInt16	nLine		Zeilennummer in dem der Fehler auftrat
106 ------------------------------------------------------------------------*/
107 
108 void AssertFail( sal_uInt16 nErrorId, const sal_Char* pFileName, sal_uInt16 nLine )
109 {
110 	// Umsetzung der ErrorId in eine Fehlermeldung
111 	static const sal_Char
112 		/* Error Fehlermeldungen zugriffe ausserhalb eines Bereiches */
113 		sERR_VAR_IDX[]		= "Op[]",
114 		sERR_OUTOFSCOPE[]	= "Zugriff ausserhalb des Bereiches",
115 		/* Error Codes fuer Numerierungsregeln */
116 		sERR_NUMLEVEL[] 	= "Falscher Num-Level",
117 		/* Error Codes fuer TxtNode */
118 		sERR_NOHINTS[]		= "Zugriff auf ungueltiges HintsArray",
119 		sERR_UNKNOWN[]		= "???";
120 
121 	static const sal_Char* aErrStrTab[ ERR_SWGMSG_END - ERR_SWGMSG_START +1 ] =
122 	{
123 		sERR_VAR_IDX, sERR_OUTOFSCOPE, sERR_NUMLEVEL, sERR_NOHINTS
124 	};
125 
126 	const sal_Char* pMsg;
127 	if( nErrorId >= ERR_SWGMSG_START && nErrorId < ERR_SWGMSG_END )
128 		pMsg = aErrStrTab[ nErrorId - ERR_SWGMSG_START ];
129 	else
130 		pMsg = sERR_UNKNOWN;
131 
132 	AssertFail( pMsg, pFileName, nLine );
133 }
134 
135 #endif // DBG_UTIL
136 
137