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