CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Try Catch

  1. #1
    Join Date
    Feb 2008
    Posts
    40

    Try Catch

    Does anyone know how to catch an exception which happens when you try to add line in database(SQL Server 2005) through binding navigator and DataGridView at the same time in VC++.

  2. #2
    Join Date
    Apr 2008
    Location
    Holland
    Posts
    51

    Re: Try Catch

    i assume you are using .net?

    if you are using System.Data.SqlClient
    have you tried catch (SqlException* e)

    http://msdn.microsoft.com/en-us/libr...on(VS.71).aspx
    Cybr@x Cybersp@ce If your found my contribution usefull please rate it.
    ------------------------------------------
    .: Whats the use of your knowledge, if you cannot share it? :.

  3. #3
    Join Date
    Feb 2008
    Posts
    40

    Re: Try Catch

    I know how to write an exception, but I don't know on which event should I write it(eg. mouse over datagridview).

  4. #4
    Join Date
    Apr 2008
    Location
    Holland
    Posts
    51

    Re: Try Catch

    Quote Originally Posted by usingnamespace
    I know how to write an exception, but I don't know on which event should I write it(eg. mouse over datagridview).


    You write the code there where you wish to catch it, sounds stupid but you need todo something before you can catch it.

    What im thinking is that you are trying to catch an exception that appears in the background or is generated by the object itself rather the programaticly or something or on a function call

    adding it to mouseover is pointless unless in that function you have code that causes the exception

    sorry i dont really understand?
    Cybr@x Cybersp@ce If your found my contribution usefull please rate it.
    ------------------------------------------
    .: Whats the use of your knowledge, if you cannot share it? :.

  5. #5
    Join Date
    Feb 2008
    Posts
    40

    Re: Try Catch

    When I press the add button on the binding navigator and then I press on the empty row in DataGridView to add another row before I even inputed data in the first. That's when the exception happens because my database doesn't allow NULLS. Now I need to somehow catch that exception.

  6. #6
    Join Date
    Apr 2008
    Location
    Holland
    Posts
    51

    Re: Try Catch

    Quote Originally Posted by usingnamespace
    When I press the add button on the binding navigator and then I press on the empty row in DataGridView to add another row before I even inputed data in the first. That's when the exception happens because my database doesn't allow NULLS. Now I need to somehow catch that exception.
    ah ok now i understand, im not 100% sure on that because i practicly never used the databindings in .net

    however a quick look at thww datagridview events (under focus) shows
    CellEnter
    CellLeave

    CellValidating

    Void dataGridView1_CellValidating(System::Object^ sender, System::Windows::Forms:ataGridViewCellValidatingEventArgs^ e)
    {

    // the pointer 'e' has a couple if items that could e of use to you
    // example
    if cell == empty then e->Cancel = true;
    }

    As i said never used them before so not sure if its any help, so i decided t take a quick look at them and i think thats the direction you should look
    Cybr@x Cybersp@ce If your found my contribution usefull please rate it.
    ------------------------------------------
    .: Whats the use of your knowledge, if you cannot share it? :.

  7. #7
    Join Date
    Feb 2008
    Posts
    40

    Re: Try Catch

    I still haven't figured out how to catch that error. Thanks anyway.

  8. #8
    Join Date
    Sep 2007
    Location
    poland|wrocław
    Posts
    47

    Re: Try Catch

    I would rather say
    Code:
    try
    {
    // some dangerous code
    }
    catch( ... )    // this should catch ANY exception
    {
    cout<<" tra la la la la la la la"
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured