Package PyFoam :: Module Error
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Error

 1  #  ICE Revision: $Id: Error.py 9616 2008-11-03 09:16:25Z bgschaid $  
 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   
13 -def getLine(up=0):
14 try: # just get a few frames 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
24 -def __common(format,standard,*text):
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
34 -def warning(*text):
35 """Prints a warning message with the occuring line number 36 @param text: The error message""" 37 __common(defaultFormat.warn,"Warning",*text)
38
39 -def error(*text):
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
45 -def debug(*text):
46 """Prints a debug message with the occuring line number 47 @param text: The error message""" 48 __common(None,"Debug",*text)
49
50 -class PyFoamException(Exception):
51 """The simplest exception for PyFoam""" 52
53 - def __init__(self,descr):
54 self.descr=descr
55
56 - def __str__(self):
57 return "Problem in PyFoam: '"+self.descr+"'"
58