exception

Logging exceptions in WCF with IErrorHandler inside HandleError or ProvideFault?

こ雲淡風輕ζ 提交于 2020-01-02 04:00:53
问题 I'm using IErrorHandler to do exception handling in WCF and now I want to log the exceptions, along with the stack trace and the user that caused the exception. The only way I can see to get the user that caused the exception is: OperationContext.Current.IncomingMessageProperties.Security.ServiceSecurityContext.PrimaryIdentity ...But this only seems to work inside ProvideFault, and not inside HandleError. Is there a way to get the user inside HandleError? I would like to use HandleError

Customising std::shared_ptr or boost::shared_ptr to throw an exception on NULL dereference

谁说我不能喝 提交于 2020-01-02 03:50:49
问题 I have a few projects that use boost::shared_ptr or std::shared_ptr extensively (I can convert to either implementation soon enough, if there is a good answer to this question for one, but not the other). The Boost implementation uses Boost.Assert to avoid returning in the case of encountering an empty (NULL) pointer in operator* or operator-> at runtime; while the libc++ implementation seems to lack any check. While of course the validity of a shared_ptr should be checked before use, a large

Android exception - Unknown origin (possibly widget)

此生再无相见时 提交于 2020-01-02 03:23:08
问题 I have the following Android exception. It is reported by Bugsense and I cannot find out where it comes from as there is no reference to any class of my app. java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0 at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251) at java.util.ArrayList.get(ArrayList.java:304) at android.widget.HeaderViewListAdapter.isEnabled(HeaderViewListAdapter.java:164) at android.widget.AbsListView$ListItemAccessibilityDelegate

“Safe handle has been closed” with SerialPort and a thread in C#

荒凉一梦 提交于 2020-01-02 02:48:06
问题 Good afternoon everybody! I have this threaded SerialPort wrapper that reads in a line from the serial port. Here is my thread's code. protected void ReadData() { SerialPort serialPort = null; try { serialPort = SetupSerialPort(_serialPortSettings); serialPort.Open(); string data; while (serialPort.IsOpen) { try { data = serialPort.ReadLine(); if (data.Length > 0) ReceivedData(serialPort, new ReceivedDataEventArgs(data)); } catch (TimeoutException) { // No action } } } catch

Best Practice way to indicate that a server request has failed?

醉酒当歌 提交于 2020-01-02 02:43:14
问题 I am writing an API that connects to a service which either returns a simple "Success" message or one of over 100 different flavors of failure. Originally I thought to write the method that sends a request to this service such that if it succeeded the method returns nothing, but if it fails for whatever reason, it throws an exception. I didn't mind this design very much, but on the other hand just today I was reading Joshua Bloch's "How to Design a Good API and Why it Matters", where he says

Add line numbers to stack trace of ASP.NET web site that is deployed in release mode

让人想犯罪 __ 提交于 2020-01-02 02:32:08
问题 I working on maintenance of one web application, this web site having error log functionality as well. My client occasionally face some issue on website which also logged in error log file but it shows only method calling hierarchy where exception occurred in stack trace. When I explicitly raise exception on my Dev environment stack trace of exception shows method calling hierarchy and its line number from where actual exception has occurred. I know in production we are deploying only DLLs

Catch exceptions which are not thrown locally?

倖福魔咒の 提交于 2020-01-02 02:26:08
问题 My question is related to syntactic behavior of the try catch block Empty try block with a catch as this void fun() { try {} catch(Exception e) {} } or try {} catch(ArrayIndexOutOfBoundsException e) {} compiles well but the compiler complains with try {} catch(IOException e) {} Why does the compiler allow catching anything that is of type Exception or RuntimeException whereas it complains for unreachable code with checked exceptions? Is it because the JVM code can throw those types? How could

Test sql connection without throwing exception

怎甘沉沦 提交于 2020-01-02 02:19:05
问题 To test if i can connect to my database, I execute the following code : using (SqlConnection connection = new SqlConnection(myConnectionString)) { try { connection.Open(); canConnect = true; } catch (SqlException) { } } This works except it throws an exception if the connection failed. Is there any other way to test a Sql connection that doesn't throw an exception ? Edit : To add precision, i'm asking if there is a simple method that does that without having to open the connection and catch

Linq, XmlNodes, foreach's and exceptions

喜夏-厌秋 提交于 2020-01-02 02:02:39
问题 Consider the following code: using System; using System.Collections.Generic; using System.Linq; using System.Xml; using System.Xml.Linq; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(@"<Parts> <Part name=""DisappearsOk"" disabled=""true""></Part> <Part name=""KeepMe"" disabled=""false""></Part> <Part name=""KeepMe2"" ></Part> <Part name=""ShouldBeGone"" disabled=""true""></Part> </Parts>"); XmlNode root

PHP try catch exceptions

主宰稳场 提交于 2020-01-02 02:01:07
问题 Hello I have a code like that : try { // Here I call my external function do_some_work() } catch(Exception $e){} The question is: If the do_some_work() has a problem and produce an Error this try catch will hide the error? 回答1: There are two types of error in PHP. There are exceptions, and there are errors. try..catch will handle exceptions, but it will not handle errors. In order to catch PHP errors, you need to use the set_error_handler() function. One way to simplify things mught be to get