exception

What is the purpose of a function try block? [duplicate]

試著忘記壹切 提交于 2020-01-01 08:49:32
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: When is a function try block useful? Difference between try-catch syntax for function This code throws an int exception while constructing the Dog object inside class UseResources . The int exception is caught by a normal try-catch block and the code outputs : Cat() Dog() ~Cat() Inside handler #include <iostream> using namespace std; class Cat { public: Cat() { cout << "Cat()" << endl; } ~Cat() { cout << "~Cat()

Visual Studio 2012 RC breaks on exceptions from within the .NET Framework. How do I make it break on exceptions only in my code?

99封情书 提交于 2020-01-01 08:48:27
问题 When debugging using Visual Studio 2012 RC with break on exception turned on, Visual Studio breaks on exceptions from within the .NET Framework. How do I make it break on exceptions only in my code? When debugging a ASP.NET MVC 4 project there are a lot of framework exceptions thrown on every page hit. The following exception happens a lot: System.Globalization.CultureNotFoundException occurred HResult=-2147024809 Message=Culture is not supported. Parameter name: name UserCache is an invalid

Why am I getting a serialization error?

左心房为你撑大大i 提交于 2020-01-01 08:46:07
问题 I have the following code: class Program { static void Main(string[] args) { string xml = @"<ArrayOfUserSetting> <UserSetting> <Value>Proposals</Value> <Name>LastGroup</Name> </UserSetting> <UserSetting> <Value>Visible</Value> <Name>WidgetsVisibility</Name> </UserSetting> </ArrayOfUserSetting>"; List<UserSetting> settings = GetObjFromXmlDocument<List<UserSetting>>(xml); } public static T GetObjFromXmlDocument<T>(string xml) { T customType; XmlSerializer serializer = new XmlSerializer(typeof(T

Why am I getting a serialization error?

别等时光非礼了梦想. 提交于 2020-01-01 08:45:58
问题 I have the following code: class Program { static void Main(string[] args) { string xml = @"<ArrayOfUserSetting> <UserSetting> <Value>Proposals</Value> <Name>LastGroup</Name> </UserSetting> <UserSetting> <Value>Visible</Value> <Name>WidgetsVisibility</Name> </UserSetting> </ArrayOfUserSetting>"; List<UserSetting> settings = GetObjFromXmlDocument<List<UserSetting>>(xml); } public static T GetObjFromXmlDocument<T>(string xml) { T customType; XmlSerializer serializer = new XmlSerializer(typeof(T

Get reference to the current exception

爱⌒轻易说出口 提交于 2020-01-01 08:39:11
问题 $ ./runtests.py -v tests/managers/test_customer.py:CustomerManagerTest.test_register_without_subscription --ipdb ... test_register_without_subscription (tests.managers.test_customer.CustomerManagerTest) ... - TRACEBACK -------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.7/unittest/case.py", line 331, in run testMethod() File "*****/tests/managers/test_customer.py", line 198, in test_register_without_subscription 1/0

Why not throw an exception if [super init] returns nil?

时光总嘲笑我的痴心妄想 提交于 2020-01-01 08:38:47
问题 This is considered typical - (id)init { self = [super init]; if (self) { // <#initializations#> } return self; } but wouldn't it be better to go with something like this which actually responds appropriately? - (id)init { self = [super init]; if (self) { // <#initializations#> } else { @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"you think your constructor is executing, but it's not"] userInfo:nil] } return self; } The corollary to this question is, "under

Looser throw specifier error in C++

狂风中的少年 提交于 2020-01-01 08:36:44
问题 The following code is generating the "Looser throw specifier error". Could you please help me to overcome this error? class base { virtual void abc() throw (exp1); } void base::abc() throw (exp1) { ...... } class sub : public base { void abc() throw(exp1, exp2); } void sub::abc() throw (exp1, exp2) { ..... } 回答1: The problem comes about because the subclass must be usable wherever the base class can be used, and so must not throw any exception types other than those specified in the base

How does C++ free the memory when a constructor throws an exception and a custom new is used

北城以北 提交于 2020-01-01 08:12:04
问题 I see the following constructs: new X will free the memory if X constructor throws. operator new() can be overloaded. The canonical definition of an operator new overload is void *operator new(size_t c, heap h) and the corresponding operator delete . The most common operator new overload is placement new, which is void *operator new(void *p) { return p; } You almost always cannot call delete on the pointer given to placement new . This leads to a single question: How is memory cleaned up when

How does C++ free the memory when a constructor throws an exception and a custom new is used

雨燕双飞 提交于 2020-01-01 08:11:48
问题 I see the following constructs: new X will free the memory if X constructor throws. operator new() can be overloaded. The canonical definition of an operator new overload is void *operator new(size_t c, heap h) and the corresponding operator delete . The most common operator new overload is placement new, which is void *operator new(void *p) { return p; } You almost always cannot call delete on the pointer given to placement new . This leads to a single question: How is memory cleaned up when

How does C++ free the memory when a constructor throws an exception and a custom new is used

纵然是瞬间 提交于 2020-01-01 08:11:09
问题 I see the following constructs: new X will free the memory if X constructor throws. operator new() can be overloaded. The canonical definition of an operator new overload is void *operator new(size_t c, heap h) and the corresponding operator delete . The most common operator new overload is placement new, which is void *operator new(void *p) { return p; } You almost always cannot call delete on the pointer given to placement new . This leads to a single question: How is memory cleaned up when