Why doesn't try..catch work on my asp.net page?
Try
Dim n As Integer = 10
n = n / 0
Catch ex As Exception
' ignore error
End Try
When I single step over the n=n/0 line, it goes straight to the standard
ASP.NET error page. Why isn't the TRY ignored?
Thanks, Rob. 21 2293
not of type Exception?
--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Rob Nicholson" <ro***********@nospam-unforgettable.com> wrote in message
news:em**************@TK2MSFTNGP09.phx.gbl... Why doesn't try..catch work on my asp.net page?
Try Dim n As Integer = 10 n = n / 0 Catch ex As Exception ' ignore error End Try
When I single step over the n=n/0 line, it goes straight to the standard ASP.NET error page. Why isn't the TRY ignored?
Thanks, Rob.
> not of type Exception?
Sorry don't understand. Same code in a VB client program goes into the Catch
section.
Thanks, Rob.
> not of type Exception?
Ahh, yes I do :-) I'm building a library function and I've created an
object/class in that called Exception. Changing it to Catch ex As
System.Exception worked.
Hmm, that's going to catch one out especially as VB creates the Catch ex as
Exception bit when you type Try<CR>. I think I'll rename my own exception
class.
Cheers, Rob.
Rob:
Funny, works for me..the exception is ignored and everything keeps
working....when I move the division outside the try/catch it craps out as
expected.
Perhaps some more context...or an actual full sample...for example, this
doesn't generate an error for me:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
</html>
<Script language="vb" runat="server">
Sub Page_Load
Try
Dim n As Integer = 10
n = n / 0
Catch ex As Exception
' ignore error
End Try
End Sub
</Script>
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/index.aspx - New and Improved (yes, the popup is
annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Rob Nicholson" <ro***********@nospam-unforgettable.com> wrote in message
news:em**************@TK2MSFTNGP09.phx.gbl... Why doesn't try..catch work on my asp.net page?
Try Dim n As Integer = 10 n = n / 0 Catch ex As Exception ' ignore error End Try
When I single step over the n=n/0 line, it goes straight to the standard ASP.NET error page. Why isn't the TRY ignored?
Thanks, Rob.
> Funny, works for me..the exception is ignored and everything keeps working....when I move the division outside the try/catch it craps out as expected.
Caught by my own cleverness or rather a bit of slack "wizard" functionality
by VB.NET
I'd created my own class called Exception so
Catch ex as Exception
Was actually:
Catch ex As Granite.Exception
Which is why it didn't work...
I actually think the VB.NET should generate a fully qualified line, i.e.
Catch ex As System.Exception
Cheers, Rob.
All Exceptions are of type Exception, just as all Objects are of type
Object.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... not of type Exception?
-- Curt Christianson Site & Scripts: http://www.Darkfalz.com Blog: http://blog.Darkfalz.com
"Rob Nicholson" <ro***********@nospam-unforgettable.com> wrote in message news:em**************@TK2MSFTNGP09.phx.gbl... Why doesn't try..catch work on my asp.net page?
Try Dim n As Integer = 10 n = n / 0 Catch ex As Exception ' ignore error End Try
When I single step over the n=n/0 line, it goes straight to the standard ASP.NET error page. Why isn't the TRY ignored?
Thanks, Rob.
I'm not sure what you mean by "it goes to the standard ASP.net error page,"
but I can tell you why no exception is being caught. None is being thrown.
In .Net, dividing any number by zero yields Infinity, and does not throw an
exception.
If your page is going to an error page, there could be another exceptin
happening in it somewhere.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
"Rob Nicholson" <ro***********@nospam-unforgettable.com> wrote in message
news:em**************@TK2MSFTNGP09.phx.gbl... Why doesn't try..catch work on my asp.net page?
Try Dim n As Integer = 10 n = n / 0 Catch ex As Exception ' ignore error End Try
When I single step over the n=n/0 line, it goes straight to the standard ASP.NET error page. Why isn't the TRY ignored?
Thanks, Rob.
> In .Net, dividing any number by zero yields Infinity, and does not throw an exception.
Err, yes it does - it generates an arithmetic overflow.
Cheers, Rob.
> All Exceptions are of type Exception, just as all Objects are of type
Thats not quite true - all exceptions are of type System.Exception.
Technically an exception object is one which inherits the
System.ApplicationException base object. Which is what we're doing - we've
inherited the exception object as we wanted to store more information with
it. It works fine through the exception chain.
Cheers, Rob.
Thanks Rob. Your post prompted me to do a little research, and it turns out
that I was partially right, and you were partially right. An attempt to
divide an integer or decimal by 0 yields a "DivideByZeroException." However,
dividing a double or a float by 0 yields Infinity, with no Exception.
However, in this case, my advice was wrong, as he was attempting to divide
an integer by 0.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
"Rob Nicholson" <ro***********@nospam-unforgettable.com> wrote in message
news:uo**************@TK2MSFTNGP09.phx.gbl... In .Net, dividing any number by zero yields Infinity, and does not throw an exception.
Err, yes it does - it generates an arithmetic overflow.
Cheers, Rob.
>> All Exceptions are of type Exception, just as all Objects are of type Thats not quite true - all exceptions are of type System.Exception.
Picky. Do you always insist on the full NameSpace in order for a statement
to be correct? You should have quit when you were ahead! ;-)
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
"Rob Nicholson" <ro***********@nospam-unforgettable.com> wrote in message
news:uI**************@TK2MSFTNGP09.phx.gbl... All Exceptions are of type Exception, just as all Objects are of type
Thats not quite true - all exceptions are of type System.Exception. Technically an exception object is one which inherits the System.ApplicationException base object. Which is what we're doing - we've inherited the exception object as we wanted to store more information with it. It works fine through the exception chain.
Cheers, Rob.
> Picky. Do you always insist on the full NameSpace in order for a statement to be correct? You should have quit when you were ahead! ;-)
In this situation the answer is "Yes". The VB.NET wizard generates the
following code when you type Try<CR>:
Try
Catch ex As Exception
End Try
That is dangerous as you might not spot that what you really need is Catch
ex As System.Exception if you *happen* to have created your own class called
Exception. Which will take precedence. The net result is that the Catch
doesn't fire and your code crashes.
Rob.
"Rob Nicholson" <ro***********@nospam-unforgettable.com> wrote in message
news:Ob**************@TK2MSFTNGP10.phx.gbl... not of type Exception?
Ahh, yes I do :-) I'm building a library function and I've created an object/class in that called Exception. Changing it to Catch ex As System.Exception worked.
Hmm, that's going to catch one out especially as VB creates the Catch ex as Exception bit when you type Try<CR>. I think I'll rename my own exception class.
Generally, that's why you'll typically see classes with names starting with
"C" e.g. CException, CRegistry, CDataAccess etc...
> In this situation the answer is "Yes".
Sloppy logic, Rob. What on earth made you think that I was somehow referring
to a class that I had created and named "Exception?" What I said was "All
Exceptions inherit Exception." From the context, it was clear that I was
referring to the ONLY "Exception" that all Exceptions inherit from. In fact,
even the original poster mentioned that his class inherits System.Exception.
It is not possible to create any type of Exception class that does NOT
inherit System.Exception, which is the base class for ALL Exceptions.
The VB.NET wizard generates the following code when you type Try<CR>:
Try Catch ex As Exception End Try
That is dangerous as you might not spot that what you really need is Catch ex As System.Exception if you *happen* to have created your own class called Exception. Which will take precedence.
Well, darn. I suppose I should switch to VB.Net and let Wizards and
Designers type all my code for me. I apologize for my ignorance. I always
write my own try/catch blocks in C#.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
"Rob Nicholson" <ro***********@nospam-unforgettable.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... Picky. Do you always insist on the full NameSpace in order for a statement to be correct? You should have quit when you were ahead! ;-)
In this situation the answer is "Yes". The VB.NET wizard generates the following code when you type Try<CR>:
Try Catch ex As Exception End Try
That is dangerous as you might not spot that what you really need is Catch ex As System.Exception if you *happen* to have created your own class called Exception. Which will take precedence. The net result is that the Catch doesn't fire and your code crashes.
Rob.
I'm with Kevin on this one...specifying System.Exception because maybe you
created your own Exception class is overkill....
Besides, how much code do you write which swollows exceptions?
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:OI****************@TK2MSFTNGP10.phx.gbl... In this situation the answer is "Yes". Sloppy logic, Rob. What on earth made you think that I was somehow
referring to a class that I had created and named "Exception?" What I said was "All Exceptions inherit Exception." From the context, it was clear that I was referring to the ONLY "Exception" that all Exceptions inherit from. In
fact, even the original poster mentioned that his class inherits
System.Exception. It is not possible to create any type of Exception class that does NOT inherit System.Exception, which is the base class for ALL Exceptions.
The VB.NET wizard generates the following code when you type Try<CR>:
Try Catch ex As Exception End Try
That is dangerous as you might not spot that what you really need is
Catch ex As System.Exception if you *happen* to have created your own class called Exception. Which will take precedence.
Well, darn. I suppose I should switch to VB.Net and let Wizards and Designers type all my code for me. I apologize for my ignorance. I always write my own try/catch blocks in C#.
-- HTH,
Kevin Spencer Microsoft MVP .Net Developer Neither a follower nor a lender be.
"Rob Nicholson" <ro***********@nospam-unforgettable.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... Picky. Do you always insist on the full NameSpace in order for a statement to be correct? You should have quit when you were ahead! ;-)
In this situation the answer is "Yes". The VB.NET wizard generates the following code when you type Try<CR>:
Try Catch ex As Exception End Try
That is dangerous as you might not spot that what you really need is
Catch ex As System.Exception if you *happen* to have created your own class called Exception. Which will take precedence. The net result is that the Catch doesn't fire and your code crashes.
Rob.
> Sloppy logic, Rob. What on earth made you think that I was somehow referring to a class that I had created and named "Exception?" What I said was "All Exceptions inherit Exception." From the context, it was clear that I was
Sloppy quoting Kevin - if you are going to quote yourself, please do it
accurately. Changing your quote from "All Exceptions are of type Exception"
(incorrect) to "All Exceptions inherit Exception" (maybe correct) doesn't
help your argument.
Colliding function names have been problem with programming languages for
many years. Namespaces do resolve them but you can only be 100% guaranteed
that you uniquely qualify something if you do you the full name.
My original post was asking "Why is the exception being captured" and the
answer is because the Catch statement wasn't fully qualified and therefore
didn't execute as expected.
Rob.
> Generally, that's why you'll typically see classes with names starting with "C" e.g. CException, CRegistry, CDataAccess etc...
Ahh, yes - that's a point of great discussion at the moment in the team. In
our last large VB6 project, all the classes were prefixed by C but that
mainly because of earlier projects in C++.
Trends change :-) I thought the C prefix was old fashioned now?
Rob.
> I'm with Kevin on this one...specifying System.Exception because maybe you created your own Exception class is overkill....
And why do you think namespaces were invented?
Rob.
> Besides, how much code do you write which swollows exceptions?
Well one would hope that if you write with code that communications with
*anything* outside of memory based variables, that you write code that traps
and therefore swallows exceptions.
Rob.
> Sloppy quoting Kevin - if you are going to quote yourself, please do it accurately. Changing your quote from "All Exceptions are of type Exception" (incorrect) to "All Exceptions inherit Exception" (maybe correct) doesn't help your argument.
Sorry Rob. The 2 phrases are equivalent. And there's no maybe about it. All
Exceptions DO inherit Exception.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
"Rob Nicholson" <ro***********@nospam-unforgettable.com> wrote in message
news:ec**************@TK2MSFTNGP09.phx.gbl... Sloppy logic, Rob. What on earth made you think that I was somehow referring to a class that I had created and named "Exception?" What I said was "All Exceptions inherit Exception." From the context, it was clear that I was
Sloppy quoting Kevin - if you are going to quote yourself, please do it accurately. Changing your quote from "All Exceptions are of type Exception" (incorrect) to "All Exceptions inherit Exception" (maybe correct) doesn't help your argument.
Colliding function names have been problem with programming languages for many years. Namespaces do resolve them but you can only be 100% guaranteed that you uniquely qualify something if you do you the full name.
My original post was asking "Why is the exception being captured" and the answer is because the Catch statement wasn't fully qualified and therefore didn't execute as expected.
Rob.
>> I'm with Kevin on this one...specifying System.Exception because maybe you created your own Exception class is overkill....
Whoa, hey, I didn't say that. I said that I didn't have to mention the
namespace IN MY MESSAGE, as it was implied. For example, people often refer
in their messages to the "Page" class, rather than "System.Web.UI.Page."
In code, it is often necessary to use full or partial namespaces when you
have assemblies containing classes or namespaces having the same name in the
same project. Rob is correct here.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
"Rob Nicholson" <ro***********@nospam-unforgettable.com> wrote in message
news:O7**************@TK2MSFTNGP10.phx.gbl... I'm with Kevin on this one...specifying System.Exception because maybe you created your own Exception class is overkill....
And why do you think namespaces were invented?
Rob. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robert |
last post by:
I have a Combobox and a DefPushButton in a PropertyPage as form (a
main window; not modal dialog)
Pressing RETURN in the Combobox or any Editfield in the form doesn't
issue a WM_COMMAND/OnOK
...
|
by: Richard \(MrBonus\) |
last post by:
the code is taken from my asp.net page. (written in C#)
Hi, im trying to make my page postback before the it unloads, i've tried a
lot of stuff, and finally I made something that worked, the...
|
by: Christopher Benson-Manica |
last post by:
(Followups set to comp.std.c. Apologies if the crosspost is unwelcome.)
strchr() is to strrchr() as strstr() is to strrstr(), but strrstr()
isn't part of the standard. Why not?
--...
|
by: Bungle |
last post by:
Hi
I am trying to do something really simple. Create a method within a
class which will connect to the database, pull back a result and
return it out the method. Not hard.
All my database...
|
by: Jim Hammond |
last post by:
The following code tries to excute a function 10 seconds after Page_Load by using a Timer, but the callback never gets called.
private void Page_Load(object sender, System.EventArgs e)
{
...
|
by: Joris De Groote |
last post by:
Hi,
I use Adobe Acrobat to read tekst from PDF files. After that the file has
been read, I move the file in a folder (using the date I got from the text I
got from Acrobat). Now here is my...
|
by: mathewda |
last post by:
Hey, I'm having a problem that I consider kinda weird that is alluding
me at the moment. I've wrote some code that will set up an
XMLHttpRequest, it then makes a call to open and send and sets the...
|
by: colyn7 |
last post by:
I really can't see what's wrong in my code... the submit() onChange doesn't work..
I've tried..
<select name="ddlTestCenter" id="ddlTestCenter" style="width:180px"...
|
by: jansi1975 |
last post by:
My scripts have been working since past 3 years. But now recently the page doesn''t work well. The page is working well under php4 in localhost but in the server side this seems to be error. on the...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |