Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.NET 2.0 Error Handling

Status
Not open for further replies.

jbenson001

Programmer
Jan 7, 2004
8,172
US
I have a question for you gurus....
I am confused in error handling in 2.0. For example, in 1.1, lets say you have a simple page, with a datagrid bound to a dataset. You can use the wizard to create the dataadapter, dataset and connection objects. Then the code is simple ..
Code:
If Not IsPostBack Then
   Try
      sda1.Fill(ds)
      datagrid1.databind
   Catch ex as Exception
      ..do something ...
   End Try
End If
Very simple and straight forward, and easy to implement the Try..Catch.
However, the question comes in using 2.0. You now drop a gridview on the page, and create a datasource and configure it and run the page. No coding involved. This is great, but how would you implement a Try...Catch since you cannot access the partial class? What if something goes wrong during the page_load, during binding? How do you trap error like this to display a message, instead of the ugly awakward defautl page?

And ideas?....
Thanks...
Jim
 
What you probably want is more of a global error handling strategy. The Application_OnError event can be handled in the Global.asax or in your own HttpModule. I personally use ELMAH for all my web error logging and handling.

See this article for more info:


Good luck!
 
T hanks. We've been using Microsoft's Enterprise Library's logging and handling code. The only thing I can't figure out is how to use a "Global" error handling routine.
 
There's a Page Error event that you could utilise if you wanted to restrict it to a particular page.

However, I prefer not to use thee "bloated" controls and write the code manually (i.e by creating a function that returns a data object and binding it myself). Personally, (and some people may disagree with this!) I think the "no coding" approach is simply a method to get beginners involved and should generally be avoided by most professional programmers.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks ca8msm. I will probably take that approach so I can control the error handling myself.
 
How are you finding the Enterprise Library Jim? I know you'd said you just started using it for a new project...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
It's going pretty good, but a little slow. The examples are are not so straige forward as I would like and finding help is not so good either. On the web, I am just finding the same thing I am finding in the documentation.
However, I did manage getting the security and exception handling working. It is great when it works, just seems like it should be eaiser to get working.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top