| 1 | package Lab::Exception; | ||
| 2 | $Lab::Exception::VERSION = '3.899'; | ||
| 3 | #ABSTRACT: Exception handling classes | ||
| 4 | |||
| 5 | use v5.20; | ||
| 6 | |||
| 7 | no strict; # FIXME | ||
| 8 | |||
| 9 | # | ||
| 10 | # un/comment the following BEGIN clause to slap in the custom base class above | ||
| 11 | # | ||
| 12 | BEGIN { $Exception::Class::BASE_EXC_CLASS = 'Lab::Exception::Base'; } | ||
| 13 | |||
| 14 | use Exception::Class ( | ||
| 15 | |||
| 16 | Lab::Exception::Error => { | ||
| 17 | description => 'An error.', | ||
| 18 | }, | ||
| 19 | |||
| 20 | # | ||
| 21 | # general errors | ||
| 22 | # | ||
| 23 | Lab::Exception::CorruptParameter => { | ||
| 24 | isa => 'Lab::Exception::Error', | ||
| 25 | description => | ||
| 26 | "A provided method parameter was of wrong type or otherwise corrupt.", | ||
| 27 | fields => [ | ||
| 28 | 'invalid_parameter', # put the invalid parameter here | ||
| 29 | ], | ||
| 30 | }, | ||
| 31 | |||
| 32 | Lab::Exception::Timeout => { | ||
| 33 | isa => 'Lab::Exception::Error', | ||
| 34 | description => | ||
| 35 | "A timeout occured. If any data was received nontheless, you can read it off this exception object if you care for it.", | ||
| 36 | fields => [ | ||
| 37 | 'data' | ||
| 38 | , # this is meant to contain the data that (maybe) has been read/obtained/generated despite and up to the timeout. | ||
| 39 | ], | ||
| 40 | }, | ||
| 41 | |||
| 42 | Lab::Exception::Unimplemented => { | ||
| 43 | description => 'An unimplemented method has been called.', | ||
| 44 | }, | ||
| 45 | |||
| 46 | # | ||
| 47 | # Driver level errors | ||
| 48 | # | ||
| 49 | Lab::Exception::DriverError => { | ||
| 50 | isa => 'Lab::Exception::Error', | ||
| 51 | description => | ||
| 52 | 'Something went wrong in the Instrument driver regime.', | ||
| 53 | fields => [], | ||
| 54 | }, | ||
| 55 | |||
| 56 | # | ||
| 57 | # errors and warnings specific to Lab::Connection::GPIB | ||
| 58 | # | ||
| 59 | Lab::Exception::GPIBError => { | ||
| 60 | isa => 'Lab::Exception::Error', | ||
| 61 | description => | ||
| 62 | 'An error occured in the GPIB connection (linux-gpib).', | ||
| 63 | fields => [ | ||
| 64 | 'ibsta', # the raw ibsta status byte received from linux-gpib | ||
| 65 | 'ibsta_hash' | ||
| 66 | , # the ibsta bit values in a named, easy-to-read hash ( 'DCAS' => $val, 'DTAS' => $val, ... | ||
| 67 | # use Lab::Connection::GPIB::VerboseIbstatus() to get a nice string representation | ||
| 68 | ], | ||
| 69 | }, | ||
| 70 | |||
| 71 | Lab::Exception::GPIBTimeout => { | ||
| 72 | isa => 'Lab::Exception::GPIBError', | ||
| 73 | description => | ||
| 74 | 'A timeout occured in the GPIB connection (linux-gpib).', | ||
| 75 | fields => [ | ||
| 76 | 'data' | ||
| 77 | , # this is meant to contain the data that (maybe) has been read/obtained/generated despite and up to the timeout. | ||
| 78 | ], | ||
| 79 | }, | ||
| 80 | |||
| 81 | # | ||
| 82 | # errors and warnings specific to VISA / Lab::VISA | ||
| 83 | # | ||
| 84 | |||
| 85 | Lab::Exception::VISAError => { | ||
| 86 | isa => 'Lab::Exception::Error', | ||
| 87 | description => | ||
| 88 | 'An error occured with NI VISA or the Lab::VISA interface', | ||
| 89 | fields => [ | ||
| 90 | 'status', # the status returned from Lab::VISA, if any | ||
| 91 | ], | ||
| 92 | }, | ||
| 93 | |||
| 94 | Lab::Exception::VISATimeout => { | ||
| 95 | isa => 'Lab::Exception::VISAError', | ||
| 96 | description => | ||
| 97 | 'A timeout occured while reading/writing through NI VISA / Lab::VISA', | ||
| 98 | fields => [ | ||
| 99 | 'status', # the status returned from Lab::VISA, if any | ||
| 100 | 'command', # the command that led to the timeout | ||
| 101 | 'data', # the data read up to the abort | ||
| 102 | ], | ||
| 103 | }, | ||
| 104 | |||
| 105 | # | ||
| 106 | # errors and warnings specific to RS232 | ||
| 107 | # | ||
| 108 | |||
| 109 | Lab::Exception::RS232Error => { | ||
| 110 | isa => 'Lab::Exception::Error', | ||
| 111 | description => 'An error occured with the native RS232 interface', | ||
| 112 | fields => [ | ||
| 113 | 'status', # the returned status | ||
| 114 | ], | ||
| 115 | }, | ||
| 116 | |||
| 117 | Lab::Exception::RS232Timeout => { | ||
| 118 | isa => 'Lab::Exception::RS232Error', | ||
| 119 | description => | ||
| 120 | 'A timeout occured while reading/writing through native RS232 interface', | ||
| 121 | fields => [ | ||
| 122 | 'status', # the status returned | ||
| 123 | 'command', # the command that led to the timeout | ||
| 124 | 'data', # the data read up to the abort | ||
| 125 | ], | ||
| 126 | }, | ||
| 127 | |||
| 128 | # | ||
| 129 | # errors and warnings specific to USB TMC | ||
| 130 | # | ||
| 131 | |||
| 132 | Lab::Exception::TMCOpenFileError => { | ||
| 133 | isa => 'Lab::Exception::Error', | ||
| 134 | description => | ||
| 135 | 'An error occured while trying to open the device file', | ||
| 136 | fields => [], | ||
| 137 | }, | ||
| 138 | |||
| 139 | # | ||
| 140 | # errors and warnings sent by devices | ||
| 141 | # | ||
| 142 | |||
| 143 | Lab::Exception::DeviceError => { | ||
| 144 | isa => 'Lab::Exception::Error', | ||
| 145 | description => "A device has reported one or more errors.", | ||
| 146 | fields => [ | ||
| 147 | 'device_class', # driver class of the device | ||
| 148 | 'command', # last command as (and if) given by the script | ||
| 149 | 'raw_message', # raw received error response (if useful) | ||
| 150 | 'error_list' | ||
| 151 | , # list of errors, of the format [ [$errcode1, $errmsg1], [$errcode2, $errmsg2]. ... ] | ||
| 152 | ], | ||
| 153 | }, | ||
| 154 | |||
| 155 | # | ||
| 156 | # general warnings | ||
| 157 | # | ||
| 158 | Lab::Exception::Warning => { description => 'A warning.' }, | ||
| 159 | |||
| 160 | Lab::Exception::UndefinedField => { | ||
| 161 | isa => 'Lab::Exception::Warning', | ||
| 162 | description => "AUTOLOAD couldn't find requested field in object", | ||
| 163 | }, | ||
| 164 | ); | ||
| 165 | |||
| 166 | 1; | ||
| 167 | |||
| 168 | __END__ |