adspace
write a code for this:trailer recordId contains a value
other than 99, then the file must error with the
reason ‘Invalid RECORD_ID’(User Defined Exception).
Answer Posted / Bipin Gupta
Here's a Python code example that defines and uses a custom exception to handle invalid record IDs.nn```pythonnclass InvalidRecordIdError(Exception):n passndef process_file(file):n trailer = file.readline().strip()n match = re.search(r'^TRAILER:s*(d{2})$', trailer)n if not match or int(match.group(1)) != 99:n raise InvalidRecordIdError('Invalid RECORD_ID')n# rest of the file processing code...``
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers