exception-handling

How to start activity from UncaughtExceptionHandler if this is main thread crashed?

喜你入骨 提交于 2019-12-05 00:26:29
问题 I am trying to start an error-reporting activty if unhandled exception detected. The problem is with exceptions thrown from main thread. Is there any way to start an activity if main thread crashed? 回答1: The approach I've seen used for error catching in an UncaughtExcpetionHandler is to write the crash data out to file and then start the error handling Activity when the application is restarted based on the existence of the crash data file. Depending on what you want your Activity to do, this

When to log exception?

ぃ、小莉子 提交于 2019-12-04 23:56:12
问题 try { // Code } catch (Exception ex) { Logger.Log("Message", ex); throw; } In the case of a library, should I even log the exception? Should I just throw it and allow the application to log it? My concern is that if I log the exception in the library, there will be many duplicates (because the library layer will log it, the application layer will log it, and anything in between), but if I don't log it in the library, it'll be hard to track down bugs. Is there a best practices for this? 回答1: I

Exception handling best practice in a windows service?

五迷三道 提交于 2019-12-04 23:51:37
I am currently writing a windows service that runs entirely in the background and does something every day. My idea is that the service should be very stable so if something goes wrong it should not stop but try it next day again and of course log the exception. Can you suggest me any best practice how to make truly stable windows services? I have read the article of Scott Hanselman of exception handling best practice where he writes that there are only few cases when you should swallow an exception. I think somehow that windows service is one of the few cases, but I would be happy to get some

What is System.ServiceModel.Diagnostics.CallbackException and why can't I handle it?

自闭症网瘾萝莉.ら 提交于 2019-12-04 23:41:20
问题 In my WCF client class I'm handling the Faulted() event so that if the remote service throws an exception and faults the channel I can still at least shut it down gracefully. Here's my code: protected void RemoteDataRetriever_Faulted(object sender, EventArgs e) { (sender as ICommunicationObject).Abort(); this.Dispose(); throw new ChannelTerminatedException("The remote service threw an unhandled exception and as a result the channel has been closed."); } So what I would expect is that the

Infinite loop invalidating the TimeManager

爱⌒轻易说出口 提交于 2019-12-04 23:39:59
I am experiencing a very tricky defect in my WPF application to track down. The error message is: An infinite loop appears to have resulted from repeatedly invalidating the TimeManager during the Layout/Render process. The stack trace (for what it's worth) is: at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading

c++ try catch practices

强颜欢笑 提交于 2019-12-04 23:36:43
Is this considered good programming practice in C++: try { // some code } catch(someException) { // do something } catch (...) { // left empty <-- Good Practice??? } No! That is a terrible practice! Just about the only time you should catch (...) and not rethrow the exception would be in main() to catch any otherwise unhandled exceptions and to display or log an error before exiting. If you catch (...) , you have absolutely no idea what exception was thrown, and thus you can't know whether it is safe to continue running. good practice is just: try { // some code } catch( const someException &

Is it bad form to raise ArgumentError by hand?

家住魔仙堡 提交于 2019-12-04 23:22:32
If you want to add an extra check not provided by argparse , such as: if variable a == b then c should be not None ...is it permissible to raise ArgumentError yourself? Or, should you raise Exception instead? Also what is common practice for this kind of situation? Say that you add a piece of code that's almost like a local extension of the library. Should you use the same exception type(s) as those provided by the library you are extending? There's nothing inherently wrong with raising an ArgumentError. You can use it anytime the arguments you receive are not what you expected them to be,

Why unhandled exception in a background thread doesnt crash the app domain?

荒凉一梦 提交于 2019-12-04 23:13:06
I am completely puzzled. I was so sure that .NET shuts the whole application domain if there is uncaught exception in a thread that I never tested this. However I just tried the following code and it doesn't fail... Could anyone please explain why? (Tried in .NET 4 and 3.5) static void Main(string[] args) { Console.WriteLine("Main thread {0}", Thread.CurrentThread.ManagedThreadId); Action a = new Action(() => { Console.WriteLine("Background thread {0}", Thread.CurrentThread.ManagedThreadId); throw new ApplicationException("test exception"); }); a.BeginInvoke(null, null); Console.ReadLine(); }

MVC5 AntiForgeryToken - how to handle “The provided anti-forgery token was meant for user ”“, but the current user is ”xxx“.” exception?

半腔热情 提交于 2019-12-04 23:10:19
I want to protect our login actions by AntiforgeryToken attribute - I know why the exception from the topic occurs, however I can't seem to find any good solution for it. Let say we have the following situations: It's 8:00 AM, application users are coming to work, they sit down and starting the login process - right now it is very possible that some of the users will get the same ValidationToken . After the first one logs in - all other will see the above exception (or some other custom exception screen) when they attempt to login. Some user logged in, then accidentally pressed the " back "

why does pthread_exit throw something caught by ellipsis?

旧巷老猫 提交于 2019-12-04 23:07:14
if the function called by pthread_create has the following structure try{ ...code.... pthread_detach(pthread_self()); pthread_exit(NULL); }catch(...){ std::cout<<"I am here"<<std::endl; } why does the exception handler for ellipsis get called at the execution of pthread_exit ? (note that std::exception , for instance, are not thrown) eran At least in GCC pthread_exit might throw an ___forced_unwind exception, that is used for unwinding the stack during the thread exit. It does not inherit from std::exception , and therefore cannot be caught as one. If you do catch that exception, be sure to re