1
2 """Standardized Error Messages"""
3
4 import traceback
5 import sys
6
7 from PyFoam.Basics.TerminalFormatter import TerminalFormatter
8
9 defaultFormat=TerminalFormatter()
10 defaultFormat.getConfigFormat("error")
11 defaultFormat.getConfigFormat("warning",shortName="warn")
12
14 try:
15 f = traceback.extract_stack(limit=up+2)
16 if f:
17 return f[0]
18 except:
19 if __debug__:
20 traceback.print_exc()
21 pass
22 return ('', 0, '', None)
23
25 """Common function for errors and Warnings"""
26 info=getLine(up=2)
27 if format:
28 print >>sys.stderr,format,
29 print >>sys.stderr, "PyFoam",standard.upper(),"on line",info[1],"of file",info[0],":",
30 for t in text:
31 print >>sys.stderr,t,
32 print >>sys.stderr,defaultFormat.reset
33
35 """Prints a warning message with the occuring line number
36 @param text: The error message"""
37 __common(defaultFormat.warn,"Warning",*text)
38
40 """Prints an error message with the occuring line number and aborts
41 @param text: The error message"""
42 __common(defaultFormat.error,"Fatal Error",*text)
43 sys.exit(-1)
44
46 """Prints a debug message with the occuring line number
47 @param text: The error message"""
48 __common(None,"Debug",*text)
49
51 """Prints a 'not implemented' message for abstract interfaces
52 @param obj: the object for which the method is not defined
53 @param name: name of the method"""
54 error("The method",name,"is not implemented in this object of type",obj.__class__)
55
57 """The simplest exception for PyFoam"""
58
61
63 return "Problem in PyFoam: '"+self.descr+"'"
64