exception-handling

How can i add property to a class dynamically

北慕城南 提交于 2020-01-02 08:33:20
问题 I want to create an error class. And it has some static properties. For example : Message , InnerException , Stacktrace , Source . But I want to add some dynamic properties. If exception is a FileNotFoundException , I want to add FileName property. Or if it is a SqlException , I want to add LineNumber property. And I can't inherit that class from Exception because, I return that class from a web service. How can I do that? 回答1: you can create type dynamically using new features in C# like

WPF global exception handler [duplicate]

那年仲夏 提交于 2020-01-02 08:05:32
问题 This question already has answers here : Globally catch exceptions in a WPF application? (6 answers) Closed 3 years ago . Sometimes, under not reproducible circumstances, my WPF application crashes without any message. The application simply close instantly. Where is the best place to implement the global Try/Catch block. At least I have to implement a messagebox with: "Sorry for the inconvenience ..." 回答1: You can handle the AppDomain.UnhandledException event EDIT: actually, this event is

Need for try catch within a constructor

淺唱寂寞╮ 提交于 2020-01-02 07:51:15
问题 The link http://gotw.ca/gotw/066.htm states that Moral #1: Constructor function-try-block handlers have only one purpose -- to translate an exception. (And maybe to do logging or some other side effects.) They are not useful for any other purpose. While http://www.parashift.com/c++-faq-lite/exceptions.html#faq-17.8 If a constructor throws an exception, the object's destructor is not run. If your object has already done something that needs to be undone (such as allocating some memory, opening

Why would Xcode 4 not be breaking on exceptions?

半城伤御伤魂 提交于 2020-01-02 07:27:14
问题 Just recently Xcode 4 has stopped breaking on exceptions. Every exception causes the debugger to stop at UIApplicationMain with no stack trace. I have a breakpoint set on objc_exception_throw (confirmed by GDB logs) Breakpoints are turned on (confirmed by GDB and other breakpoints work fine) LLVM GCC 4.2 is my compiler Enable Objective-C Exceptions is turned on Are there any reasons breakpoints may not be working? Any flags I'm missing? 回答1: In Xcode 4, you add the breakpoint for exceptions

Memory exception while XDocument.Save()

こ雲淡風輕ζ 提交于 2020-01-02 07:12:13
问题 I am trying to save an XDcoument to a thumb drive which doesnt have enough memory space available. (This is a special test condition for the app) Though the application is giving an exception like below, I cant get that in the try catch block around the XDocument.Save(filePath). Looks like it is a delayed throw. Is it a LINQ issue or am I doing something wrong?. alt text http://img211.imageshack.us/img211/8324/exce.png System.IO.IOException was unhandled Message="There is not enough space on

How can I clean up my exception handling?

痞子三分冷 提交于 2020-01-02 06:55:23
问题 I'm looking to clean up the exception mess that is currently the code base I'm working on. The basic setup is this. I have an interface that is implemented by a lot of classes that looks like this: public interface TerminalMessage<E> { // Override for specific return data type. public E send(TerminalStream stream) throws Exception; } These classes throw a lot of different exceptions, like IOException, InterruptedException etc. As it is now, all I do is call getMessage() on the catched

How can i get the error number instead of error message in an Exception in C#? [duplicate]

不羁岁月 提交于 2020-01-02 05:58:34
问题 This question already has answers here : How to get Exception Error Code in C# (5 answers) Closed 6 years ago . Is there a way that i can get the corresponding error code of an Exceptions ? I need the thrown exceptions error code instead of its message , so that i based on the error code i show the right message to the user. 回答1: If you're looking for the win32 error code, that's available on the Win32Exception class catch (Win32Exception e) { Console.WriteLine("ErrorCode: {0}", e.ErrorCode);

GetWindowText() throwing error and not being caught by try/catch

一个人想着一个人 提交于 2020-01-02 05:58:09
问题 When I run the code below for the GetWindowText I get the following error thrown as an inner Exception: {"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."} [DllImport("user32.dll", EntryPoint = "GetWindowTextLength", SetLastError = true)] internal static extern int GetWindowTextLength(IntPtr hwnd); [DllImport("user32.dll", EntryPoint = "GetWindowText", SetLastError = true)] internal static extern int GetWindowText(IntPtr hwnd, ref

Exception handling strategy - reuse exception codes

不想你离开。 提交于 2020-01-02 05:35:07
问题 I'm working on an application where the process goes on like this UI --> backend process --> result to UI. In my Java code, I have handled my exceptions using try-catch, But in the code I have so many repeated exceptions that may throw same exceptions in different classes, which reduces the readability and code reuse. So, I am planning to do a exception handling strategy so that instead of throwing the same exception in different classes, I need to organize the exception and reuse the

How do we handle Python xmlrpclib Connection Refused?

心已入冬 提交于 2020-01-02 05:08:08
问题 I don't know what the heck I'm doing wrong here, I wrote have an RPC client trying to connect to a non-existent server, and I'm trying to handle the exception that is thrown, but no matter what I try I can't figure out how I'm supposed to handle this: def _get_rpc(): try: a = ServerProxy('http://dd:LNXFhcZnYshy5mKyOFfy@127.0.0.1:9001') a = a.supervisor return a except: return False rpc = _get_rpc() if not rpc: print "No RPC" Since there is no server running, I would expect the output to be