exception-handling

Lifecycle of thrown exceptions in C++

喜欢而已 提交于 2019-12-12 15:12:06
问题 Consider the following simple C++ code: void foo() { throw(my_exception()); } void check_exc(const my_exception &exc) { /* Do stuff with exc */ } void bar() { try { foo(); } catch(const my_exception &exc) { check_exc(exc); } } In bar 's exception handler, how comes the exception referenced by exc is still alive, seeing as how it was allocated in foo 's stack frame? Shouldn't that frame have been unwound by the time the exception handler gets to run, and any values allocated there already be

How to Handle Exceptions thrown in AsyncCalls function without calling .Sync?

自作多情 提交于 2019-12-12 14:22:10
问题 When I am using AsyncCalls, how do you best get the exception into the main thread? For example: procedure TUpdater.needsToGoFirst(); begin asyncCall := TAsyncCalls.Invoke(procedure begin //some stuff if (possiblyTrueCondition = True) then raise Exception.Create('Error Message'); //more stuff TAsyncCalls.VCLSync(procedure begin notifyUpdates(); end); end); end; procedure TUpdater.needsToGoSecond(); begin asyncCall2 := TAsyncCalls.Invoke(procedure begin //initial stuff asyncCall.Sync(); /

Android Espresso : correctly test closing app with pressBack

拜拜、爱过 提交于 2019-12-12 14:17:27
问题 I'm trying to implement some navigation tests with espresso. Actually i want to check if the application has been closed by the use of the Back key on the main screen, just after a fresh start. Here is a piece of code i'm using. class NavigationTests { @get:Rule val mActivityTestRule: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java) @Test fun backOnEmptyHomeMustExit(){ Espresso.pressBack() Assert.assertTrue(mActivityTestRule.activity==null) } } Actually i got a test

Exception Handling in Ada during Unit Test

空扰寡人 提交于 2019-12-12 13:08:59
问题 I am attempting to write some unit tests for some Ada code I recently wrote, I have a particular case where I am expecting to get an Exception (if the code worked correctly I wouldn't but in this case all I'm doing is testing, not writing code). If I handle the exception in the Testing routine then I don't see how I can continue testing in that procedure. I.E. (This is very much an example and NOT compilable code) procedure Test_Function is begin from -20 to 20 Result := SQRT(i); if Result =

Where to catch exceptions

跟風遠走 提交于 2019-12-12 12:28:20
问题 I have a WCF svc separated into a Service Layer, Business Logic Layer and Data Access Layer. When my DAL encounters an exception, should I catch it there or let it bubble back up to the Service Layer? And why? Please disregard any client involvement for this scenario, I am only concerned with logging the exceptions on the WCF svc. 回答1: It depends also on how you are architecting your solution. For instance, if the DAL and BLL layers are meant to be totally independent components, then they

Android : Can I use this intent from a 3rd party application?

笑着哭i 提交于 2019-12-12 12:20:35
问题 I'm using an intent to post a message via a Twitter client. When there is no Twitter application on the phone I want to redirect the user to the market. But the exception ActivityNotFoundException is not working. Everytime (when I don't have a Twitter app) I get the error "No applications can perform this action" Intent intentTwitter = new Intent(Intent.ACTION_SEND); intentTwitter.putExtra(Intent.EXTRA_TEXT,msg); intentTwitter.setType("application/twitter"); try{ startActivity(Intent

Catching general exceptions

南楼画角 提交于 2019-12-12 12:17:11
问题 According to this MSDN article, you should not catch general exceptions. I'm sure there's a stackoverflow question dealing with that, and I understand why it's not a good practice but I just saw this example on another MSDN article today: using System; using System.IO; class Test { public static void Main() { try { using (StreamReader sr = new StreamReader("TestFile.txt")) { String line = sr.ReadToEnd(); Console.WriteLine(line); } } catch (Exception e) { Console.WriteLine("The file could not

WCF fault handling

给你一囗甜甜゛ 提交于 2019-12-12 11:41:13
问题 Q How can I get the original exception (occurred on the server) on the client side? I am working with a self-hosted WCF service and C# 4 and trying to set up proper exception handling. I have a client that looks like this private ServiceResponse PerformRemoteAction(ServiceRequest request, ProcessOperations operation) { ... try { //remote call switch (operation) { ... case ProcessOperations.VerifyAction: { response = client.VerifyAction(request); break; } default: throw new

Using class object as generic type

余生颓废 提交于 2019-12-12 11:35:09
问题 I'm not entirely sure of how to ask this question, which is also why I'm not sure about the title and so on. Here goes. Say you have a object Foo foo = new Foo() . Is it possible to write code like new ArrayList<foo.getClass()>() , which would on runtime be equivalent to new ArrayList<Foo>() ? Another, but related question is: Suppose that the class Foo extends Exception . Is it then possible to write something like try{ // ... } catch(foo.getClass() e) { // } which would translate into try{

exception handling on background threads using Thread pool

会有一股神秘感。 提交于 2019-12-12 11:33:43
问题 The application I am working on uses thread pool. Here's the basic pseudo code. On the main thread foreach(Object obj in Component.GetObject()) { //Invoke the thread pool providing the call back (method to be called on the background// thread) and pass the object as the parameter. } //Wait for the threads to complete. The "Component.GetObject" will basically return a CLR object using Yield return. This object needs to be processed by two other components on threads. So we are invoking the