Error handling

I

Iams

When your program gets an error, is there a name of that Exception somewhere
on that error page so that you can trap it with the correct exception name?
For instance, I errored when attempting to bind a grid, because a field
didn't exist in the query that was on the grid. How do I find the name of
the exception and trap the error? The error I received said:

A field or property with the name 'ID' was not found on the selected
datasource.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: A field or property with the
name 'ID' was not found on the selected datasource.

Source Error:


Line 314: HTTPContext.Current.Session("DS") = ds
Line 315: dgrid.DataSource = ds
Line 316: dgrid.DataBind()
Line 317:
Line 318: End Sub


Source File: C:\Inetpub\wwwroot\WebApplication1\default.aspx Line: 316

Stack Trace:


[HttpException (0x80004005): A field or property with the name 'ID' was not
found on the selected datasource.]
System.Web.UI.WebControls.BoundColumn.OnDataBindColumn(Object sender,
EventArgs e) +346
System.Web.UI.Control.OnDataBinding(EventArgs e) +66
System.Web.UI.Control.DataBind() +26
System.Web.UI.Control.DataBind() +86
System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32
dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,
DataGridColumn[] columns, TableRowCollection rows, PagedDataSource
pagedDataSource) +169
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean
useDataSource) +1408
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +48
System.Web.UI.WebControls.BaseDataList.DataBind() +23
 
K

Kevin Spencer

How do I find the name of
the exception and trap the error?
Exception Details: System.Web.HttpException:

...and you can catch it with either a Try/Catch block, or fix it by fixing
your code.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.


Iams said:
When your program gets an error, is there a name of that Exception
somewhere
on that error page so that you can trap it with the correct exception
name?
For instance, I errored when attempting to bind a grid, because a field
didn't exist in the query that was on the grid. How do I find the name of
the exception and trap the error? The error I received said:

A field or property with the name 'ID' was not found on the selected
datasource.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: A field or property with the
name 'ID' was not found on the selected datasource.

Source Error:


Line 314: HTTPContext.Current.Session("DS") = ds
Line 315: dgrid.DataSource = ds
Line 316: dgrid.DataBind()
Line 317:
Line 318: End Sub


Source File: C:\Inetpub\wwwroot\WebApplication1\default.aspx Line: 316

Stack Trace:


[HttpException (0x80004005): A field or property with the name 'ID' was
not
found on the selected datasource.]
System.Web.UI.WebControls.BoundColumn.OnDataBindColumn(Object sender,
EventArgs e) +346
System.Web.UI.Control.OnDataBinding(EventArgs e) +66
System.Web.UI.Control.DataBind() +26
System.Web.UI.Control.DataBind() +86
System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32
dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,
DataGridColumn[] columns, TableRowCollection rows, PagedDataSource
pagedDataSource) +169
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean
useDataSource) +1408
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +48
System.Web.UI.WebControls.BaseDataList.DataBind() +23
 
I

Iams

The code isn't my problem, I have other users who modify the database that
the program is hitting, so I need specific error messages, in this case, the
fact that someone deleted a column that my datagrid is referring to. How do
I distinguish between an error where a column is missing and any other
datagrid errors I may encounter? I want the program to do different things
depending on what caused the error. Do I have to interpret the actual
message, like we did in old vb, to fire events based on what the actual
error is? I guess what I'm looking for are already-built exceptions, like
the ArgumentOutOfRangeException, or ArgumentNullexception you can use when
values are empty.

Try
dgrid.DataBind()
Catch ex as System.Web.HttpException 'error due to missing column in
database
HTTPContext.Current.Session("Status") = ex.Message
End Try



Kevin Spencer said:
How do I find the name of
the exception and trap the error?
Exception Details: System.Web.HttpException:

..and you can catch it with either a Try/Catch block, or fix it by fixing
your code.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Neither a follower nor a lender be.


Iams said:
When your program gets an error, is there a name of that Exception
somewhere
on that error page so that you can trap it with the correct exception
name?
For instance, I errored when attempting to bind a grid, because a field
didn't exist in the query that was on the grid. How do I find the name of
the exception and trap the error? The error I received said:

A field or property with the name 'ID' was not found on the selected
datasource.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: A field or property with the
name 'ID' was not found on the selected datasource.

Source Error:


Line 314: HTTPContext.Current.Session("DS") = ds
Line 315: dgrid.DataSource = ds
Line 316: dgrid.DataBind()
Line 317:
Line 318: End Sub


Source File: C:\Inetpub\wwwroot\WebApplication1\default.aspx Line: 316

Stack Trace:


[HttpException (0x80004005): A field or property with the name 'ID' was
not
found on the selected datasource.]
System.Web.UI.WebControls.BoundColumn.OnDataBindColumn(Object sender,
EventArgs e) +346
System.Web.UI.Control.OnDataBinding(EventArgs e) +66
System.Web.UI.Control.DataBind() +26
System.Web.UI.Control.DataBind() +86
System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex, Int32
dataSourceIndex, ListItemType itemType, Boolean dataBind, Object dataItem,
DataGridColumn[] columns, TableRowCollection rows, PagedDataSource
pagedDataSource) +169
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean
useDataSource) +1408
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +48
System.Web.UI.WebControls.BaseDataList.DataBind() +23
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top