exception-handling

ContinueWith TaskContinuationOptions.OnlyOnFaulted does not seem to catch an exception thrown from a started task

好久不见. 提交于 2019-12-05 13:16:10
I'm trying to catch an exception thrown from a task method using ContinueWith and OnlyOnFaulted like below. However I get an unhandled exception while I try to run this code. I'd like the task to run to completion since I have handled the exception already. But Task.Wait() runs into AggregateException. var taskAction = new Action(() => { Thread.Sleep(1000); Console.WriteLine("Task Waited for a sec"); throw (new Exception("throwing for example")); }); Task t = Task.Factory.StartNew(taskAction); t.ContinueWith(x => Console.WriteLine("In the on Faulted continue with code. Catched exception from

Exception handling strategy - reuse exception codes

霸气de小男生 提交于 2019-12-05 13:03:46
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 exception codes. Could anyone suggest me best exception handling technique to do this? Always handle Unchecked

How to throw an exception by its run-time type?

こ雲淡風輕ζ 提交于 2019-12-05 12:44:55
I want to call a function that may throw an exception. If it does throw an exception, I want to catch it and pass the exception object to a handler function. The default implementation of the handler function is simply to throw the exception. Here is whittled-down code to illustrate the issue: struct base_exception : exception { char const* what() const throw() { return "base_exception"; } }; struct derived_exception : base_exception { char const* what() const throw() { return "derived_exception"; } }; void exception_handler( base_exception const &e ) { throw e; // always throws a base

Monotouch Global Exception handling

五迷三道 提交于 2019-12-05 12:30:12
问题 I am having a nasty bug show up in the wild, and I can't put my finger on it. Is there a way to have a Global Try/Catch block, or a way to handle any exception that is unhanded in Monotouch. Can I just wrap UIApplication.Main(args) in a try catch? After the exception is caught, Id like to show a UIAlertView to display the results. Any help? 回答1: You can wrap UIApplication.Main (args) in a try {} catch {} but you will not be able to show a UIAlertView at that point, since we've unwound the

Getting sensible info from CLR-to-SEH exceptions in a mixed mode C++ project

吃可爱长大的小学妹 提交于 2019-12-05 12:29:22
Mixed mode C++ project. Native code is calling managed code. Managed code might throw an exception. I can catch said exception in native mode using a vectored exception handler; I can see its PEXCEPTION_POINTERS . The telling code 0xE0434F4D, meaning it's a CLR exception, is there. Question: is there any way to get any sensible information (exception class, message, stack trace etc.) from the attendant data? There's one parameter in the ExceptionInformation , and it looks like a pointer to something... No, that's too late. All you got is the exception code. You might get something in

In C# (or .NET in general) can you mask the call stack level where an exception was thrown via attributes?

对着背影说爱祢 提交于 2019-12-05 12:22:28
The title may be a little confusing so I'll explain. Say you had this call chain... public DoWork(index) >> private DoWorkHelper(index) >> private CheckIndex(index) Now if you call DoWork , it traverses the calls down to CheckIndex , adding each deeper call to the call stack. Now if someone calls DoWork with a bad value for index , it throws the exception all the way down at CheckIndex , and currently, that's where the debugger breaks. You then have to walk back up the call stack to see the real offender was that someone passed bad data to DoWork . Now back in the VB6 days, you could simply

Exception handling in RIA Service

北慕城南 提交于 2019-12-05 12:18:31
问题 As you know, it's recomended handle exceptions using FaultException with standard WCF service to hide exception details. That's fine but i'm having problem with WCF Ria service. I want to throw an exception from domain service and the client will handle that exception. I want to avoid disclosing exception's sensitive information such as stack trace, method names etc. If it were standard WCF service, I'd use FaultException exception, but in Ria service, it's not working. No matter what kind of

Try-catch-finally order of execution appears to be random [duplicate]

[亡魂溺海] 提交于 2019-12-05 12:09:48
问题 This question already has an answer here : Why does the execution order between the printStackTrace() and the other methods appear to be nondeterministic? (1 answer) Closed 4 years ago . I am trying to understand how the try-catch-finally execution flow works. There are a couple of solutions from Stack Overflow users regarding their execution flow. One such example is: try { // ... some code: A } catch(...) { // ... exception code: B } finally { // finally code: C } Code A is going to be

Handling Unknown Errors in protractor

人走茶凉 提交于 2019-12-05 11:37:02
I have a protractor setup with multiple browsers configured through multiCapabilities , running tests on browserstack. One of my key protractor specs/tests contain the following afterEach() block: afterEach(function() { browser.manage().logs().get("browser").then(function (browserLog) { expect(browserLog.length).toEqual(0); }); }); that checks that the browser console is empty (no errors on the console). The problem is : when I run this spec against Internet Explorer, I'm getting an UnknownError : UnknownError: Command not found: POST /session/6b838fe8-f4a6-4b31-b245-f4bf8f37537c/log After a

What is it called when I say “catch (Exception e) {}” in Java?

大兔子大兔子 提交于 2019-12-05 11:34:53
I am not sure about this answer. I cant find it anywhere. Is it the empty error handling?! It is known as suppressing the exception, or swallowing the exception. May not be a very good practice, unless commented with a very good reason. We affectionately call this "eating the exception" at work. Basically, it means that something bad occurred, and we are burying our head in the sand and pretending it never happened. At the very least, a good practice is to have a logger.error(e) within that block: try { // code here } catch (Exception e) { logger.error(e); } so that you will have it recorded