I have a method that A) inserts a row in a table and then B) uses the resulting Identity value in several inserts in another table. If the logic in part B fails for any reason, I need to rollback all of the inserts for both parts B and A. I'm fairly certain that transactions would not work for this, although I'm open to being persuaded...
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 rethr...
Are there any rules of thumb as to how many catch statements you'd expect per source line of code in a large piece of software?
For instance, in one piece of software written in C#, Visual Studio shows up about 350 lines containing the word "catch", and cloc reports that we have about 160k SLOC, 30k commented lines, and 15k blank lines....
Hi, I've just seen a question on try-catch, which people (including Jon Skeet) say empty catch blocks are a really bad idea? Why this? Is there no situation where an empty catch is not a wrong design decision?
I mean, for instance, sometimes you want to get some additional info from somewhere (webservice, database) and you really don't ...
Please, see this answer to see the main problem.
How can you solve the following error message in prepared statement?
I have a index.php to which I put data through many handlers. The following error message occurs at the following URL that is a URL after a login form.
http://localhost/codes/index.php?ask_question&email=masi.mas...
Hi,
How can i catch sigpipe in iphone/objective-c?
thanks
...
This question is close to what I want to do, but not quite there.
Is there a way to simplify the following code?
private bool ValidDirectory(string directory)
{
if (!Directory.Exists(directory))
{
if (MessageBox.Show(directory + " does not exist. Do you wish to create it?", this.Text)
== DialogResult.OK)
...
So I use Qt a lot with my development and love it. The usual design pattern with Qt objects is to allocate them using new.
Pretty much all of the examples (especially code generated by the Qt designer) do absolutely no checking for the std::bad_alloc exception. Since the objects allocated (usually widgets and such) are small this is har...
During a code review with a Microsoft employee we came across a large section of code inside a try{} block. She and an IT representative suggested this can have effects on performance of the code. In fact, they suggested most of the code should be outside of try/catch blocks, and that only important sections should be checked. The Micros...
Mentally, I've always wondered how try/throw/catch looks behind the scenes, when the C++ compiles translates it to assembler. But since I never use it, I never got around to checking it out (some people would say lazy).
Is the normal stack used for keeping track of try's, or is a separate per-thread stack kept for this purpose alone? Is...
I just found in a project:
try
{
myLabel.Text = school.SchoolName;
}
catch
{
myPanel.Visible = false;
}
I want to talk to the developer than wrote this, saying that incurring the null exception (because school might theoretically be null, not myLabel) would virtually make the computer beep three times and sleep for two seconds...
Hello all!
How do i check if a result is of the right type(int, float, double, etc.) and then throw and catch an exception in case it's not?
Thanks all,
Vlad.
...
I'd like a response from someone who actually does real-time programming in C# or who really understands the language internals.
I know that exceptions should not be used to handle normal processing, but only to detect error conditions. There is plenty of discussion on that topic.
I'd like to know if there is any run time slow-down fr...
Hi, when I'm trying to getimagesize($img) and the image dos't exist I get an error. I don't wont to first check if the file exist, just handle the error.
I'm not sure how try-catch works, but I wont to do like:
try: getimagesize($img) $works = true
catch: $works = flase
...
Our team recently upgraded to TeamCity 4.5.4 but we're having trouble with TeamCity running our nant build scripts.
We now get an error message saying: Invalid element <trycatch>. Unknown task or datatype.
We haven't changed our build script during or after the upgrade so I'm wondering what, if any, change do we need to make to get thi...
Why are some methods in Java not caught by Catch(Exception ex). This is code is completely failing out with an unhandled exception. (Java Version 1.4).
public static void main(String[] args)
{
try {
//Code ...
}catch (Exception ex) {
System.err.println("Caught Exception");
ex.printStackTrace();
exitCode = app.FAILURE_E...
SQL Server 2008 has a new try/catch structure. If I encounter an error in a sequence of nested stored procedures, I like to log the call stack in an error table. The problem is that if I have started a transaction (which will be true for operations that update the db), an records written to the error table will be removed when the code...
Hi,
I have sql server procedure, please see below.
ALTER PROCEDURE [dbo].[uspInsertDelegate]
(
@CourseID int,
@CPUserID int,
@StatusID int,
@CreateUser varchar(25)
)
AS
SET NOCOUNT OFF;
INSERT INTO tblDelegate
(
CourseID,
CPUserID,
StatusID,
CreateUser
)
VALUES
(
...
Say I have some code that does this:
Public Function AppendToLogFile(ByVal s As String) As Boolean
Dim success As Boolean = True
Dim fs As IO.FileStream = Nothing
Dim sw As IO.StreamWriter = Nothing
Static LogFileLock As New Object()
SyncLock LogFileLock
Try
fs = New IO.FileStream(LogFilePath)
...
My first route:
// Should work for /Admin, /Admin/Index, /Admin/listArticles
routes.MapRoute(
"Admin", // Route name
"Admin/{action}", // URL with parameters
new { controller = "Admin", action = "Index" } // Parameter defaults
);
is not re...