Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Why doesn't try..catch work on my web page?

Reply
Thread Tools

Why doesn't try..catch work on my web page?

 
 
Rob Nicholson
Guest
Posts: n/a
 
      03-01-2005
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.


 
Reply With Quote
 
 
 
 
Curt_C [MVP]
Guest
Posts: n/a
 
      03-01-2005
not of type Exception?

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com


"Rob Nicholson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
 
 
 
Rob Nicholson
Guest
Posts: n/a
 
      03-01-2005
> not of type Exception?

Sorry don't understand. Same code in a VB client program goes into the Catch
section.

Thanks, Rob.


 
Reply With Quote
 
Rob Nicholson
Guest
Posts: n/a
 
      03-01-2005
> 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.


 
Reply With Quote
 
Karl Seguin
Guest
Posts: n/a
 
      03-01-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
Rob Nicholson
Guest
Posts: n/a
 
      03-01-2005
> 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.


 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      03-02-2005
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:%(E-Mail Removed)...
> not of type Exception?
>
> --
> Curt Christianson
> Site & Scripts: http://www.Darkfalz.com
> Blog: http://blog.Darkfalz.com
>
>
> "Rob Nicholson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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.
>>

>
>



 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      03-02-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
Rob Nicholson
Guest
Posts: n/a
 
      03-02-2005
> 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.


 
Reply With Quote
 
Rob Nicholson
Guest
Posts: n/a
 
      03-02-2005
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
why why why does function not work Horace Nunley ASP .Net 1 09-27-2006 09:52 PM
Re: WHY, WHY WON'T IT WORK??? Marina ASP .Net 2 06-29-2004 02:40 PM
Why oh why doesn't my data view work? David Prowak ASP .Net 1 01-30-2004 04:19 AM



Advertisments