How to catch IndentationError Exception in python?

Manogna
Updated on 12-Feb-2020 10:43:35

946 Views

A IndentationError occurs any time the parser finds source code that does not follow indentation rules. We can catch it when importing a module, since the module will be compiled on first import. You can't catch it in the same module that contains the try/except block, because with this exception, Python won't be able to finish compiling the module, and no code in the module will be run.We rewrite the given code as follows to handle the exceptionExampletry: def f(): z=['foo', 'bar'] for i in z: if i == 'foo': except IndentationError as e: print eOutput"C:/Users/TutorialsPoint1/~.py", line 5 if i ... Read More

How to catch ZeroDivisionError Exception in Python?

Rajendra Dharmkar
Updated on 12-Feb-2020 10:42:53

407 Views

When zero shows up in the denominator of a division operation, a ZeroDivisionError is raised.We re-write the given code as follows to handle the exception and find its type.Exampleimport sys try: x = 11/0 print x except Exception as e: print sys.exc_type print eOutput integer division or modulo by zero

How to catch FloatingPointError Exception in Python?

Rajendra Dharmkar
Updated on 12-Feb-2020 10:42:09

1K+ Views

FloatingPointError is raised by floating point operations that result in errors, when floating point exception control (fpectl) is turned on. Enabling fpectl requires an interpreter compiled with the --with-fpectl flag.The given code is rewritten as follows to handle the exception and find its type.Exampleimport sys import math import fpectl try: print 'Control off:', math.exp(700) fpectl.turnon_sigfpe() print 'Control on:', math.exp(1000) except Exception as e: print e print sys.exc_type OutputControl off: 1.01423205474e+304 Control on: in math_1

How to catch StandardError Exception in Python?\\\\

Rajendra Dharmkar
Updated on 12-Feb-2020 10:41:26

363 Views

There is the Exception class, which is the base class for StopIteration, StandardError and Warning. All the standard errors are derived from StandardError. Some standard errors like ArithmeticErrror, AttributeError, AssertionError are derived from base class StandardError.When an attribute reference or assignment fails, AttributeError is raised. For example, when trying to reference an attribute that does not exist:We rewrite the given code and catch the exception and know it type.Exampleimport sys try: class Foobar: def __init__(self): self.p = 0 f = Foobar() print(f.p) print(f.q) except Exception as e: print e print sys.exc_type print 'This is an example of StandardError exception'Output0 Foobar ... Read More

How to catch StopIteration Exception in Python?

Rajendra Dharmkar
Updated on 12-Feb-2020 10:40:43

1K+ Views

When an iterator is done, it’s next method raises StopIteration. This exception is not considered an error.We re-write the given code as follows to catch the exception and know its type.Exampleimport sys try: z = [5, 9, 7] i = iter(z) print i print i.next() print i.next() print i.next() print i.next() except Exception as e: print e print sys.exc_type Output 5 9 7

How to catch SystemExit Exception in Python?

Rajendra Dharmkar
Updated on 12-Feb-2020 10:39:46

2K+ Views

In python documentation, SystemExit is not a subclass of Exception class. BaseException class is the base class of SystemExit. So in given code, we replace the Exception with BaseException to make the code workExampletry: raise SystemExit except BaseException: print "It works!"OutputIt works!The exception inherits from BaseException instead of StandardError or Exception so that it is not accidentally caught by code that catches Exception.We would rather write the code this wayExampletry: raise SystemExit except SystemExit: print "It works!"OutputIt works!

How to catch NotImplementedError Exception in Python?

Rajendra Dharmkar
Updated on 12-Feb-2020 10:36:48

1K+ Views

User-defined base classes can raise NotImplementedError to indicate that a method or behavior needs to be defined by a subclass, simulating an interface. This exception is derived from RuntimeError. In user defined base classes, abstract methods should raise this exception when they require derived classes to override the method.Exampleimport sys try:    class Super(object):         @property         def example(self):             raise NotImplementedError("Subclasses should implement this!")    s = Super()    print s.example except Exception as e:     print e     print sys.exc_typeOutputSubclasses should implement this!

How to call a jQuery plugin function outside the plugin?

Amit D
Updated on 12-Feb-2020 10:31:35

266 Views

jQuery is a JavaScript library introduced to make development with JavaScript easier. It reduces the development time. Let us see how to call a jQuery plugin function outside the plugin.For calling, wrap the jQuery method for returning the instance of the constructor. Call prototype methods on it.example$.fn.myFunction = function(config){     return new myFunction (config); };Instance the plugin and call the method −var plugin = $('#someSelector').myFunction(); plugin.setToken(column);

SAP ABAP: Using Elementary data type and reference type with keyword VALUE

SAP Expert
Updated on 12-Feb-2020 10:28:09

186 Views

It is not possible. Check this link for details:ABAP DocumentationThe correct way for using “VALUE” with elementary data type is by assigning initial value and you should use NEW operator to assign initial value.DATA(l_value) = NEW char4( 'AAA' ).

Data Replication from SAP PO to SQL Server

SAP Expert
Updated on 12-Feb-2020 10:24:40

333 Views

Note that SAP PO is not a data source but middleware so it doesn’t contain any data. You can extract data from SQL Server using JDBC.SAP PI/XI enables you to set up cross system communication and integration and allows you to connect SAP and non-SAP systems based on different programming language like Java and SAP ABAP. It provides an open source environment that is necessary in complex system landscape for the integration of systems and for communication.SAP Process Integration is a middleware to allow seamless integration between SAP and non-SAP application in a company or with systems outside the company.ExampleAn ... Read More

Advertisements