|
Any ideas on this one? I'm trying to write a unit test that will delete an item and confirm that item is no longer in a repository by trying to retrieve the item by its ID which should throw a DataAccessException. However, the test keeps failing. I added...
Started by Justin Holbrook on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
[TestMethod] [ExpectedException....
The VS Unit Test Framework will only look for an ExpectedException attribute at the entry point of a particular test .
You need to add the ExpectedException attribute onto the same method which has the TestMethod attribute .
|
|
In c++, Iam trying to catch all types of exceptions in one catch (like catch(Exception) in C#). how is it done ? and more, how can one catch devide-by-zero exceptions ?
Started by gil on
, 8 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
catch(...) will also ....
}
Important considerations:
A better approach is to catch specific types of exception that you can actually recover from as opposed to all possible exceptions.
catch (...) { // Handle exceptions not covered.
|
|
Which one should I use?
catch (_com_error e)
or
catch (_com_error& e)
Started by Corey Trager on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Try { throw MyException....
Here is my attempt at quoting Sutter
"Throw by value, catch by reference"
Here's MyException ("error") } catch (Exception e) { /* Implies: Exception e (MyException ("error by not copying the exception.
The second.
|
Ask your Facebook Friends
|
In the try catch block is it bad practice to return values from the catch block in C++?
try { //Some code... return 1; } catch(...) { return 0; }
Which method of using try/catch is good practice?
Started by shankara on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Write:
int rc = 1; try { // some code } catch(...) { rc = 0; } return rc;
I find it easier to debug on the end of the function, after the try/catch block..
|
|
What is the difference between
try { } catch { throw; }
and
try { } catch(Exception e) { throw e;}
and when should i use one or another?
Started by Karim on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
You would normally use....
You should use
try { } catch(Exception e) { throw }
if you want to do stack trace.
catch (Exception ex) { throw new Exception("Additional information...", ex); }
There's a blog post discussing the differences.
|
|
I have question about throw. How will the throw work in the following code? Does the catch block return false?
try { //code } catch(Exception ex) { throw; return false; }
Answer Snippets (Read the full thread at stackoverflow):
If your client code looks something be doing this instead:
try { bankAccount... .
Let's assume your try/catch is in a BankAccount class.
The return false is never reached at the same time .
Somewhere up the call stack needs to catch it.
No, it rethrows.
|
|
Possible Duplicate:
Why catch and rethrow Exception in C#?
I sometimes come across C# code that looks like this:
try { // Some stuff } catch (Exception e) { throw e; }
I understand its possible to do something like log the exception message and then rethrow...
Started by Justin Dearing on
, 13 posts
by 13 people.
Answer Snippets (Read the full thread at stackoverflow):
But this is often used to do other things in the catch the exact same exception:
catch (Exception) { throw; }
Whereas this rethrows the exception without the original stack trace:
catch....
Not if you do nothing else in the catch...
|
|
Hi
We recently had a problem with a Java server application where the application was throwing Errors which were not caught because Error is a separate subclass of Throwable and we were only catching Exceptions.
We solved the immediate problem by catching...
Answer Snippets (Read the full thread at stackoverflow):
An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch
Normally when programming, you should....
That indicates conditions that a reasonable application might want to catch.
|
|
I have often come across situations like :-
try{ ... stmts ... } catch(Exception ex) { ... stmts ... } finally { connection.close // throws an exception }
which still needs a try - catch block inside finally.
What is the best practice to overcome this...
Started by Ajay on
, 8 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
Write a SQLUtils class that contains static closeQuietly methods ... .
} finally { connection.close(): } } catch before the catch but I think it solves the problem you were trying to solve.
Stmts ...
I usually did it this way:
try { try { . .
|
|
I have some PHP code that should cause and catch two exceptions:
try{ @$this->connector->connect(); // Suppress the default warning (doesn't effect 'throw') } catch(BadArgumentException $e) {} // Works, no error, following code executes. try{ @$...
Started by Minty on
, 3 posts
by 3 people.
Answer Snippets (Read the full thread at stackoverflow):
OK I found out it was a namespacing problem: it seems PHP doesn't complain when you try and use a non-existant namespaced element (in this case use Framework\AuthenticationException when really I needed use Framework\Connector\AuthenticationException ... .
|