Click here to Skip to main content
15,891,033 members
Home / Discussions / C#
   

C#

 
AnswerRe: Arrhgg.. C++ DLLs make me angry.. Pin
Paul Conrad21-Sep-07 16:46
professionalPaul Conrad21-Sep-07 16:46 
GeneralRe: Arrhgg.. C++ DLLs make me angry.. Pin
Dio2221-Sep-07 17:16
Dio2221-Sep-07 17:16 
AnswerRe: Arrhgg.. C++ DLLs make me angry.. Pin
Paul Conrad22-Sep-07 4:58
professionalPaul Conrad22-Sep-07 4:58 
GeneralRe: Arrhgg.. C++ DLLs make me angry.. Pin
Dio2222-Sep-07 8:50
Dio2222-Sep-07 8:50 
QuestionOleDbConnection question Pin
ForkOffandDie21-Sep-07 4:37
ForkOffandDie21-Sep-07 4:37 
AnswerRe: OleDbConnection question Pin
Colin Angus Mackay21-Sep-07 5:01
Colin Angus Mackay21-Sep-07 5:01 
GeneralRe: OleDbConnection question Pin
ForkOffandDie21-Sep-07 5:05
ForkOffandDie21-Sep-07 5:05 
AnswerRe: OleDbConnection question Pin
Scott Dorman21-Sep-07 5:15
professionalScott Dorman21-Sep-07 5:15 
ForkOffandDie wrote:
if calling Dispose() results in an implicit call to Close()


This can not be a blanket statement as it isn't always true. In this particular case, the Dispose method on OleDbConnection does actually call Close. There are other instances where this does not occur so you need to read the documentation carefuly or use a tool like Reflector to verify what the code actually does.

Keep in mind that your code is actually changed by the compiler so the using statements are replaced by try/finally blocks. It ends up looking similar to this:
C#
try
{
    if (table != null)
    {
        OleDbConnection connection;
        try
        {
            connection = new OleDbConnection();
            connection.Open();

            OleDbCommand command;
            try
            {
                command = connection.CreateCommand();
                command.CommandText = "SELECT obj From " + table.Alias;

                OleDbDataReader reader;
                try
                {
                    reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        container.Add(new Feature((xx)reader.Getxx(0)));
                    }
                }
                finally
                {
                    if (reader != null)
                    {
                        ((IDisposable)reader).Dispose();
                    }
                }
            }
            finally
            {
                if (command != null)
                {
                    ((IDisposable)command).Dispose();
                }
            }
        }
        finally
        {
            if (connection != null)
            {
                ((IDisposable)connection).Dispose();
            }
        }
    }
}
catch (Exception)
{
    MessageBox.Show("There was a GPS Error");
}
When an exception occurs, the runtime begins a two-step process:
  1. The runtime searches the array for the first protected block that:
    • Protects a region that includes the currently executing instruction, and
    • Contains an exception handler or contains a filter that handles the exception.

  2. If a match occurs, the runtime creates an Exception object that describes the exception. The runtime then executes all finally or fault statements between the statement where the exception occurred and the statement handling the exception. Note that the order of exception handlers is important: the innermost exception handler is evaluated first. Also note that exception handlers can access the local variables and local memory of the routine that catches the exception, but any intermediate values at the time the exception is thrown are lost.


    If no match occurs in the current method, the runtime searches each caller of the current method, and it continues this path all the way up the stack. If no caller has a match, the runtime allows the debugger to access the exception. If the debugger does not attach to the exception, the runtime raises the UnhandledException event. If there are no listeners for the UnhandledException event, the runtime dumps a stack trace and ends the program.
(Exceptions Overview (MSDN)[^]

So, effectively what this says is that when an exception occurs, the runtime walks the stack backwards looking for a catch block that can handle that exception until it finds one or reaches to top of the stack and raises an UnhandledException. If it does find one, it then runs any finally blocks it found leading up to the catch block and then runs the catch block.

Sorry for the long-winded answer, but if I understand you correctly, it would seem that your line of reasoning is correct. The finally blocks would run, which would close the objects and then run the catch handler and display the message box.

ForkOffandDie wrote:
What would have priority over a thrown exception such that it HAD to process before a catch was allowed to handle the Exception?


I'm not sure this really makes sense. Processing the catch block is handling the exception. The finally blocks really don't have anything to do with what exception was thrown as they will execute no matter what, even if no exceptions were thrown. The Framework does have a concept of Filtered exception handlers, but that isn't supported by C# (only VB and IL, as far as I know).



Scott.

—In just two days, tomorrow will be yesterday.

[Forum Guidelines] [Articles] [Blog]

GeneralRe: How to use LoadFile method of RichTextbox ? Pin
nesaver8521-Sep-07 3:56
nesaver8521-Sep-07 3:56 
QuestionPrinttoprinter Pin
Saamir21-Sep-07 3:49
Saamir21-Sep-07 3:49 
AnswerRe: Printtoprinter Pin
Ravi Bhavnani21-Sep-07 3:59
professionalRavi Bhavnani21-Sep-07 3:59 
GeneralRe: Printtoprinter Pin
Saamir21-Sep-07 4:16
Saamir21-Sep-07 4:16 
Questionsaving graph as an xml file Pin
Mamphekgo Bahula21-Sep-07 3:25
Mamphekgo Bahula21-Sep-07 3:25 
AnswerRe: saving graph as an xml file Pin
Ravi Bhavnani21-Sep-07 4:01
professionalRavi Bhavnani21-Sep-07 4:01 
QuestionHow to use LoadFile method of RichTextbox ? Pin
nesaver8521-Sep-07 3:23
nesaver8521-Sep-07 3:23 
AnswerRe: How to use LoadFile method of RichTextbox ? Pin
Luc Pattyn21-Sep-07 3:45
sitebuilderLuc Pattyn21-Sep-07 3:45 
GeneralRe: How to use LoadFile method of RichTextbox ? Pin
nesaver8521-Sep-07 4:28
nesaver8521-Sep-07 4:28 
GeneralRe: How to use LoadFile method of RichTextbox ? Pin
Luc Pattyn21-Sep-07 5:14
sitebuilderLuc Pattyn21-Sep-07 5:14 
AnswerRe: How to use LoadFile method of RichTextbox ? Pin
Pete O'Hanlon21-Sep-07 3:50
mvePete O'Hanlon21-Sep-07 3:50 
QuestionProblem in TreeView Pin
stancrm21-Sep-07 2:18
stancrm21-Sep-07 2:18 
AnswerRe: Problem in TreeView Pin
DaveyM6921-Sep-07 2:24
professionalDaveyM6921-Sep-07 2:24 
QuestionDirectoryInfo UNC Path Pin
TheShihan21-Sep-07 2:18
TheShihan21-Sep-07 2:18 
AnswerRe: DirectoryInfo UNC Path Pin
TJoe21-Sep-07 2:57
TJoe21-Sep-07 2:57 
GeneralRe: DirectoryInfo UNC Path Pin
TheShihan21-Sep-07 3:14
TheShihan21-Sep-07 3:14 
GeneralRe: DirectoryInfo UNC Path Pin
TJoe21-Sep-07 3:29
TJoe21-Sep-07 3:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.