Error class and add functionality

Assignment Help Basic Computer Science
Reference no: EM132288474

Complete the Error, SyntaxError, and ZeroDivisionError classes such that they create the correct messages when called.

  • The SyntaxError and ZeroDivisionError classes inherit from the Error class and add functionality that is unique to those particular errors. Their code is partially implemented for you.
  • The add_code method adds a new helpful message to your error, while the write method should print the output that you see when an error is raised.
  • You can access the parent class methods using the super() function
class Error:
    """
    >>> err1 = Error(12, "error.py")
    >>> err1.write()
    'error.py:12'

    """
    def __init__(self, line, file):
        "*** YOUR CODE HERE ***"

    def write(self):
        return self.file + ':' + str(self.line)

class SyntaxError(Error):
    """
    >>> err1 = SyntaxError(17, "HW10.py")
    >>> err1.write()
    HW10.py:17 SyntaxError : Invalid syntax
    >>> err1.add_code(4, "EOL while scanning string literal")
    >>> err2 = SyntaxError(18, "HW10.py", 4)
    >>> err2.write()
    HW10.py:18 SyntaxError : EOL while scanning string literal

    """
    type = 'SyntaxError'
    msgs = {0 : "Invalid syntax", 1: "Unmatched parentheses", 2: "Incorrect indentation", 3: "missing colon"}

    def __init__(self, line, file, code=0):
        "*** YOUR CODE HERE ***"

    def write(self):
        end = self.type + ' : ' + self.message
        "*** YOUR CODE HERE ***"

    def add_code(self, code, msg):
        "*** YOUR CODE HERE ***"

class ZeroDivisionError(Error):
    """
    >>> err1 = ZeroDivisionError(273, "HW10.py")
    >>> err1.write()
    HW10.py:273 ZeroDivisionError : division by zero
    """
    type = 'ZeroDivisionError'

    def __init__(self, line, file, message='division by zero'):
        "*** YOUR CODE HERE ***"

    def write(self):
        end = self.type + ' : ' + self.message
        "*** YOUR CODE HERE ***"

Reference no: EM132288474

Questions Cloud

Difficulties in troubleshooting dns errors : The difficulties in troubleshooting DNS errors. so how do i fix this difficulties in troubleshooting DNS errors.
Discuss the five processes of project management : Discuss the five (5) processes of project management. As a manager, how would you plan, track, and manage projects, and what software could you use?
Why is it important to sign saml assertions : Why is it important to sign SAML Assertions? Why is it not important to sign OAuth Access Tokens?
Provide an example of a project selection form : Explain project management terms, tools, and techniques that are applicable to the pre-planning/project selection stage.
Error class and add functionality : Complete the Error, SyntaxError, and ZeroDivisionError classes such that they create the correct messages when called.
Structured format and numbering in listing requirements : Document a complete list of functional requirements (non-functional requirements are not required). Be specific and describe your requirements
Can we have different conceptual schema designs : Can we have different conceptual schema designs (i.e., ERDs) for the same application?
How involvement of minors makes issue more problematic : Conduct a scholarly literature search of your issue to find a minimum of three references in addition to the Learning Resource you have selected in order.
Find out the equation of motion of the cylinder : 301021 Advanced Thermal and Fluid Engineering Assignment - Project, Western Sydney University, Australia. Find out the equation of motion of the cylinder

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Confidential negotiations with another company

Your company is engaged in confidential negotiations with another company. In what wayscould rivals use sniffing to get this commercially sensitive data? For each way say what youcould do to minimise the risk.

  Huge amounts of resources on data over the years

Your organizations has invested huge amounts of resources on Data over the years. There are many databases, legacy systems, reporting applications, mix of in-house developed and off-the shelf software.

  Equation for equilibrium i in the goods market

Derive an equation for equilibrium i in the goods market. Write in words how the interest rate is determined by loanable funds in the goods market.

  How to return a result from a vb function

1. Define what arguments are in reference to VB functions and subroutines.

  What interval should be scheduled for maintenance

What interval should be scheduled for maintenance to minimize the overall equivalent annual cost? The interest rate is 8% per year.

  Develop a recursive implementation

Develop a recursive implementation that incorporates the ideas above for calculating the Fibonacci number. Compare the performance of the recursive method with the iterative solution.

  Key facts about short-run economic fluctuations

Using Western Metals Recycling as the corporation; identify the three key facts about short-run economic fluctuations

  Describe what each of the two-dimensional characters

Describe what each of the two-dimensional characters might represent and the data that would be held in the array. Also, provide an example array declaration.

  Improve a company business model

How is Virtualization used to improve a company business model?

  Manage your personal checking account

Consider the process of using an online banking system to manage your personal checking account.

  Positive-length intervals

Recall that in the Activity Selection problem we are given it positive-length intervals beginning and ending at integer values

  More efficient way to create a midiheap

How can you code for a more efficient way to create a midiheap?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd