| 1 |
# ######################################################################## |
| 2 |
# Copyright 2013 Advanced Micro Devices, Inc. |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
# you may not use this file except in compliance with the License. |
| 6 |
# You may obtain a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
# See the License for the specific language governing permissions and |
| 14 |
# limitations under the License. |
| 15 |
# ######################################################################## |
| 16 |
|
| 17 |
#---------------------------------File Note------------------------------------ |
| 18 |
#Date: 27 January 2012 |
| 19 |
#This file defines all the error code and error handler mechanism |
| 20 |
#--------------------------------Global Variables------------------------------ |
| 21 |
|
| 22 |
UINS_CAT = 100 |
| 23 |
WIN_REG_SEARCH_FAIL = 101 |
| 24 |
UNIMPL_APP = 200 |
| 25 |
SYS_ERR = 300 |
| 26 |
TIME_OUT = 400 |
| 27 |
DIM_INCO_FILE_FMT = 500 #incorrect file format for dimension |
| 28 |
DIM_FILE_VAL_INCO = 501 #Value coming from dimension file is incorrect |
| 29 |
|
| 30 |
#__errorTable : Defines all the errors in the system. Add a new error code and |
| 31 |
# error message here |
| 32 |
"""Error table is defined as private to this module""" |
| 33 |
errorTable = { |
| 34 |
UINS_CAT: 'Application is not able to find the installed catalyst', |
| 35 |
WIN_REG_SEARCH_FAIL: 'Windows Registry search for catalysts version is unsuccessful', |
| 36 |
UNIMPL_APP: 'Unimplemented Application requirement', |
| 37 |
SYS_ERR: 'System error occurred - Please check the source code', |
| 38 |
TIME_OUT: 'Operation is timed out', |
| 39 |
DIM_INCO_FILE_FMT: 'incorrect file format for dimension - Not able to find dimension', |
| 40 |
DIM_FILE_VAL_INCO: 'Value coming from dimension file is incorrect' |
| 41 |
} |
| 42 |
|
| 43 |
#--------------------------------Class Definitions----------------------------- |
| 44 |
class TimeoutException(Exception): |
| 45 |
pass |
| 46 |
|
| 47 |
"""Base class for handling all the application generated exception""" |
| 48 |
class ApplicationException(Exception): |
| 49 |
|
| 50 |
def __init__(self, fileName, errno, msg = ""): |
| 51 |
self.fileName = fileName |
| 52 |
self.errno = errno |
| 53 |
self.mess = errorTable[errno] + msg |
| 54 |
self.message = 'Application ERROR:'+repr(self.fileName+'-'+str(self.errno)+'-'+self.mess) |
| 55 |
|
| 56 |
def __str__(self): |
| 57 |
return repr(self.fileName+'-'+str(self.errno)+'-'+self.mess) |
| 58 |
|
| 59 |
|
| 60 |
#--------------------------------Global Function------------------------------- |
| 61 |
if __name__ == '__main__': |
| 62 |
#print errorTable |
| 63 |
try: |
| 64 |
raise ApplicationException('errorHandler', SYS_ERR) |
| 65 |
|
| 66 |
except: |
| 67 |
print 'Generic exception' |
| 68 |
|