exception-handling

What SAFESEH:NO option actually do

北城余情 提交于 2019-12-08 15:07:22
问题 I'm trying to use boost::asio::spawn function like in the example, but it gives me the following error in Release: libboost_context-vc120-mt-s-1_55.lib(jump_i386_ms_pe_masm.obj) : error LNK2026: module unsafe for SAFESEH image It is clear that I should set /SAFESEH:NO option in the project's settings but I can't understand what this will actually do. How this affect the behavior of exception handling in the program (both C++ exceptions and SEH)? btw I'm using MSVC-12.0. 回答1: Short answer:

How to rethrow a prior exception from inside a nested try-catch block? (C#)

偶尔善良 提交于 2019-12-08 15:05:34
问题 I have code that attempts a type conversion. If it fails, I want to try something else, and if that also fails, then rethrow the original exception attempted by the first conversion. The problem is that the only way I know of to rethrow is to have ' throw; ' sitting at the end of the catch block. What happens when I only want the rethrow to happen from within another catch block? try { valueFromData = Convert.ChangeType(valueFromData, pi.PropertyType); } catch(InvalidCastException e) { Debug

Serialize XML same tag twice

倖福魔咒の 提交于 2019-12-08 15:02:45
问题 I've the problem: I have to serialize class to XML file. But two properties must be named with the same name: Desired xml: <?xml version="1.0"?> <Test> <HeaderText> <Tag1>AAA</Tag1> </HeaderText> <HeaderText> <Tag2>BBB</Tag2> </HeaderText> </Test> I don't need to deserialize it back to object. Code: public class Header1 { [XmlElement("Tag1")] public String Tag1 { get; set; } } public class Header2 { [XmlElement("Tag2")] public String Tag2 { get; set; } } public class Test { [XmlElement(

C# Exception Handling Fall Through [duplicate]

可紊 提交于 2019-12-08 14:58:00
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Catch multiple Exceptions at once? Is there any way in C# to easily achieve the following pseduo-code: try { ... } catch ( ExceptionTypeA, ExceptionTypeB, ExceptionTypeC as ex) { ... same code for all threw } Or try { ... } catch ( ExceptionTypeA ex ) catch ( ExceptionTypeB ex ) catch ( ExceptionTypeC ex ) { ... same code for all exceptions of A, B or C } I guess what I'm saying would be great would be fall

XML Serialization error: 2 types both use the XML type name, 'Relationship', from namespace ''

给你一囗甜甜゛ 提交于 2019-12-08 14:52:07
问题 I am having a problem serializing via XML because 2 clases use a class (although different classes!) called Relationship. I have tried decorating 1 of the classes with another name using the XML attribute but it still gives me the following error: {"Types 'SiteServer.Relationship' and 'LocalServer.Relationship' both use the XML type name, 'Relationship', from namespace ''. Use XML attributes to specify a unique XML name and/or namespace for the type."} Here are my 2 classes, anyone know why ?

Arrays.copyOfRange method in java throws incorrect exception

六眼飞鱼酱① 提交于 2019-12-08 14:39:47
问题 I was working on arrays today and suddenly I came across a scenario throwing unexpected exceptions. If you look at the code below , I think it must throw ArrayIndexOutOfBoundsException , but surprisingly it is throwing IllegalArgumentException instead: import java.util.Arrays; public class RangeTest { public static void main(String[] args) { int[] a = new int[] {0,1,2,3,4,5,6,7,8,9}; int[] b = Arrays.copyOfRange(a, Integer.MIN_VALUE, 10); // If we'll use Integer.MIN_VALUE+100 instead Integer

Catch python 'ImportError' if import from source directory

我是研究僧i 提交于 2019-12-08 14:32:03
问题 When one tries to import a module foo while being in the source directory, one gets an rather confusing ImportError message: ImportError: No module named foo . How can I easily catch this case and return a more informative message, e.g. 'Please do not load module foo from the source directory'? Having the __init__.py , I would start with: try: from _foo import * except ImportError: ## check whether in the source directory... So I would like to distinguish the different causes for an

Google Analytics Android SDK / Exceptions report : “myParser represents your implementation of ExceptionParser”

风格不统一 提交于 2019-12-08 13:35:17
问题 I have implemented in my project the exception reporting feature of Google Analytics (Android SDK) described here : https://developers.google.com/analytics/devguides/collection/android/v2/exceptions?hl=fr I would like to use ExceptionParser as explained at the bottom of the page but I don't understand what they mean by : // Where myParser represents your implementation of ExceptionParser. ExceptionParser parser = new myParser(context); What should I write in the myParser class ?? Why this

Translating exceptions for Task<T> with Task Parallel Library a la await

依然范特西╮ 提交于 2019-12-08 12:35:39
问题 I'm trying to do the equivalent of the dollowing C# 5 pseudocode:- async Task<int> CallAndTranslate() { try { return await client.CallAsync(); } catch(FaultException ex) { if (ex.FaultCode ...) throw new Exception("translated"); } } Given an arbitrary Task which does not return a result, translating exceptions when backporting from C# 5 is easy using the technique supplied by @Drew Marsh This technique doesn't generalize trivially to Task<T> as any overload of Task.ContinueWith I can see

log4net not logging and throwing error

不想你离开。 提交于 2019-12-08 12:00:09
问题 I have been using log4Net to write in a text file when there is any exception in my web service, this was working but today it started to throw error. System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.TypeInitializationException: The type initializer for.. threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'log4net, Version=1.2.9.0, Culture=neutral, PublicKeyToken=b32731d11ce58905' or one of its dependencies. The