How to get the name of an exception that was caught in Python?

How can I get the name of an exception that was raised in Python? e.g., try: foo = bar except Exception as exception: name_of_exception = ??? assert name_of_exception == ‘NameError’ print “Failed with exception [%s]” % name_of_exception For example, I am catching multiple (or all) exceptions, and want to print the name of the exception … Read more

How do you catch this exception?

This code is in django/db/models/ It creates/defines an exception? class ReverseSingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjectDescriptorMethods)): # This class provides the functionality that makes the related-object # managers available as attributes on a model class, for fields that have # a single “remote” value, on the class that defines the related field. # In the example “choice.poll”, the poll attribute … Read more

What is ApplicationException for in .NET?

To throw exceptions, I usually use built-in exception classes, e.g. ArgumentNullException and NotSupportedException. However, sometimes I need to use a custom exception and in that case I write: class SlippedOnABananaException : Exception { } class ChokedOnAnAppleException : Exception { } and so on. Then I throw and catch these in my code. But today I … Read more

Android, ListView IllegalStateException: “The content of the adapter has changed but ListView did not receive a notification”

What I want to do: run a background thread which calculates ListView contents and update ListView partially, while results are calculated. What I know I have to avoid: I cannot mess with ListAdapter contents from background thread, so I inherited AsyncTask and publish result (add entries to adapter) from onProgressUpdate. My Adapter uses ArrayList of … Read more

Adding information to an exception?

I want to achieve something like this: def foo(): try: raise IOError(‘Stuff ‘) except: raise def bar(arg1): try: foo() except Exception as e: e.message = e.message + ‘happens at %s’ % arg1 raise bar(‘arg1’) Traceback… IOError(‘Stuff Happens at arg1’) But what I get is: Traceback.. IOError(‘Stuff’) Any clues as to how to achieve this? How … Read more

Visual Studio: How to break on handled exceptions?

I would like Visual Studio to break when a handled exception happens (i.e. I don’t just want to see a “First chance” message, I want to debug the actual exception). e.g. I want the debugger to break at the exception: try { System.IO.File.Delete(someFilename); } catch (Exception) { //we really don’t care at runtime if the … Read more