p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

aspdotnet_website_programming thread: Don't understand Error Handling in this bbok..


Message #1 by dougwood@a... on Thu, 20 Mar 2003 22:14:01
I am just very curious as to why there are 3 different areas in this site 
that are dealing with Error Handling.
Global.asax
AppException.cs (base class)
PhilePage.cs

All 3 of these have almonst the exact same code for error handling.

so WHAT is the difference???!!. What exactly is happening when an error 
occurs in the ThePhile?. Why are there 3 different areas that are dealing 
with Exception???
Someone set me straight please!!

Thanks!
Message #2 by "Blue Tiger" <bluetiger@m...> on Thu, 20 Mar 2003 17:25:33 -0500
I was wondering that as well...
Even more, I want an alternative to using the IIS log, since all of us 
don't
have access to that specifically. How can I rewrite the C# code so that 
I
can log it all to a text file or even a separate table in the database?
Any ideas?

-----Original Message-----
From: dougwood@a... [mailto:dougwood@a...]
Sent: Thursday, March 20, 2003 10:14 PM
To: Website Programming with ASP.NET
Subject: [aspdotnet_website_programming] Don't understand Error Handling 
in
this bbok..

I am just very curious as to why there are 3 different areas in this 
site
that are dealing with Error Handling.
Global.asax
AppException.cs (base class)
PhilePage.cs

All 3 of these have almonst the exact same code for error handling.

so WHAT is the difference???!!. What exactly is happening when an error
occurs in the ThePhile?. Why are there 3 different areas that are 
dealing
with Exception???
Someone set me straight please!!

Thanks!
---
Professional Design Patterns in VB.NET:
Building Adaptable Applications

Want to know how design patterns bring reusable
design and adaptabilty to your applications? How
to recognize the need for a design pattern
solution? How to select, design, and implement
the right patterns? How parts of the .NET Framework
(like the .NET Data Providers and .NET Remoting)
take advantage of design patterns? This book
presents a practical approach to using design
patterns in VB.NET, by focusing on the relevance
of design patterns in the different tiers of a
distributed n-tier architecture.

http://www.wrox.com/books/1861006985.htm


Message #3 by ryan@e... on Fri, 21 Mar 2003 00:40:51
To send error messages to a text file use a System.IO.TextWriter class. It 
can write asequential series of characters. 
Here is an example of creating a new text file:

***************************************************************
        FileInfo t = new System.IO.FileInfo("YourFileName.txt");
	StreamWriter Tex = t.CreateText();
	Tex.WriteLine("This file begins the error messages file.");
	Tex.WriteLine("csharp is the coding language of choice.");
	Tex.Write(Tex.NewLine);
	Tex.Close();
***************************************************************
The text file will be created right next to your executable assembly.

Now that the text file exists, use the FILEINFO.APPENDTEXT to open the 
file to add your error messaged. You may want to use a try/catch/finally 
block to catch exceptions.

***************************************************************
	FileInfo t = new FileInfo("YourFileName.txt");
	StreamWriter Tex = t.AppendText();
	Tex.WriteLine("Your error message!);
	Tex.Write(Tex.NewLine);
	Tex.Close();
***************************************************************

It's amazing how little code is needed to perform these functions.


To send messages to an xml file, use the xmlwriter or xmltextwriter 
classes.

To save the messages to a database you will use the System.Data, 
System.Data.OLEDB and/or System.Data.SQLClient classes, depending on the 
type of database you use. These classes will include connection objects 
and may include data adapters and command builders. To learn more about 
these classes check out this resource:

http://www.dotnet247.com/247reference/default.aspx

I hope that this helps.

Ryan Stevens
Gilford, NH

> I was wondering that as well...
Even more, I want an alternative to using the IIS log, since all of us 
don't
have access to that specifically. How can I rewrite the C# code so that 
I
can log it all to a text file or even a separate table in the database?
Any ideas?

-----Original Message-----
From: dougwood@a... [mailto:dougwood@a...]
Sent: Thursday, March 20, 2003 10:14 PM
To: Website Programming with ASP.NET
Subject: [aspdotnet_website_programming] Don't understand Error Handling 
in
this bbok..

I am just very curious as to why there are 3 different areas in this 
site
that are dealing with Error Handling.
Global.asax
AppException.cs (base class)
PhilePage.cs

All 3 of these have almonst the exact same code for error handling.

so WHAT is the difference???!!. What exactly is happening when an error
occurs in the ThePhile?. Why are there 3 different areas that are 
dealing
with Exception???
Someone set me straight please!!

Thanks!
---
Professional Design Patterns in VB.NET:
Building Adaptable Applications

Want to know how design patterns bring reusable
design and adaptabilty to your applications? How
to recognize the need for a design pattern
solution? How to select, design, and implement
the right patterns? How parts of the .NET Framework
(like the .NET Data Providers and .NET Remoting)
take advantage of design patterns? This book
presents a practical approach to using design
patterns in VB.NET, by focusing on the relevance
of design patterns in the different tiers of a
distributed n-tier architecture.

http://www.wrox.com/books/1861006985.htm


Message #4 by ryan@e... on Fri, 21 Mar 2003 00:50:51
I forgot to mention, the FileInfo class can also determine whether a file 
exists or not. Like this   'FileInfo.Exists("Filename.txt");' Then your 
logic can determine whether it should create the file or simply add to it. 

Ryan


> I am just very curious as to why there are 3 different areas in this 
site 
t> hat are dealing with Error Handling.
G> lobal.asax
A> ppException.cs (base class)
P> hilePage.cs

> All 3 of these have almonst the exact same code for error handling.

> so WHAT is the difference???!!. What exactly is happening when an error 
o> ccurs in the ThePhile?. Why are there 3 different areas that are 
dealing 
w> ith Exception???
S> omeone set me straight please!!

> Thanks!
Message #5 by dougwood@a... on Fri, 21 Mar 2003 06:38:34
That's good info about writing to a text FIle, thanks,
but I stilll don't understand why there are 3 separate areas for catching 
Errors!
what is the difference???
Message #6 by "Scott Willsey" <hangtown@t...> on Sun, 23 Mar 2003 11:33:31 -0800
The difference is that they are used by different error types.  The
exception class is used if the program works as intended, but you want
to throw an exception due to not liking the data you are getting.  The
error handling in the base page is used if the page does not execute due
to an error that would normally show an asp.net error based on your
customErrors mode.

Not sure about the one in the global.asax as I do not use it... I don't
know how it differs from the one in the base page. 
 
-----Original Message-----
From: dougwood@a... [mailto:dougwood@a...] 
Sent: Friday, March 21, 2003 6:39 AM
To: Website Programming with ASP.NET

That's good info about writing to a text FIle, thanks, but I stilll
don't understand why there are 3 separate areas for catching Errors!
what is the difference???
---
Professional Design Patterns in VB.NET: 
Building Adaptable Applications

Want to know how design patterns bring reusable design and adaptabilty
to your applications? How to recognize the need for a design pattern
solution? How to select, design, and implement the right patterns? How
parts of the .NET Framework (like the .NET Data Providers and .NET
Remoting) take advantage of design patterns? This book presents a
practical approach to using design patterns in VB.NET, by focusing on
the relevance of design patterns in the different tiers of a distributed
n-tier architecture. 

http://www.wrox.com/books/1861006985.htm

---
Change your mail options at http://p2p.wrox.com/manager.asp or to
unsubscribe send a blank email to



Message #7 by ryan@e... on Mon, 24 Mar 2003 00:47:14
Hey Doug, The handler in the Global.asax.cs file handles all errors by 
objects that do not inherit the handler in the PhilePage.cs class.

Use a throw here and there along with some breakpoints in the error 
handlers to perform your own tests. 

throw(new ArgumentNullException());

use that to raise errors. Try it in the Default.aspx.cs file's Page_Load 
event, then in the Global.asax.cs files Application_Start event.

I can only guess that the authors wanted to follow OOP principals and let 
their pages inherit the error handler of PhilePage.cs class, then they 
found that not all objects had access to the handler, hence the handler in 
Global.asax.cs.

You must be a member of the debuggers group in 2000 or XP to use the 
debugger in VS.NET

Hope that this helps!
Ryan Stevens
Gilford, NH



> That's good info about writing to a text FIle, thanks,
b> ut I stilll don't understand why there are 3 separate areas for 
catching 
E> rrors!
w> hat is the difference???
Message #8 by dougwood@a... on Mon, 24 Mar 2003 07:01:37
Thanks guys, that makes things clearer for me!

  Return to Index