Err.raise, how do I filter out custom error numbers...

257 views
Skip to first unread message

Digs

unread,
Jan 21, 2010, 12:40:24 AM1/21/10
to ELMAH
HI,

I am using ELMAH in my asp.net project...vb.net

Great tool, thanks

BUT..

I error creation code like

err.raise(-999,"MyFile.aspx","This is the wrong info !")

I use try and catch around this code.

BUT I would like to filter out all custom error numbers under ZERO..

This filer code didnt do it...

<errorFilter>
<test>
<equal binding="HttpStatusCode" value="404" type="Int32" />
<and>
<lesser binding="HttpStatusCode" value="0" type="Int32" />
</and>
</test>
</errorFilter>

Any ideas how to do this...

Atif Aziz

unread,
Jan 21, 2010, 7:28:40 AM1/21/10
to el...@googlegroups.com
This is what you may have intended instead:

<errorFilter>
  <test>
    <or>
      <equal binding="HttpStatusCode" value="404" type="Int32" />
      <lesser binding="HttpStatusCode" value="0" type="Int32" />
    </or>
  </test>
</errorFilter>

- Atif


--
You received this message because you are subscribed to the Google Groups "ELMAH" group.
To post to this group, send email to el...@googlegroups.com.
To unsubscribe from this group, send email to elmah+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/elmah?hl=en.




Digs

unread,
Jan 22, 2010, 12:55:44 PM1/22/10
to ELMAH
Thanks for a response..

However it seams that err.raise(-999, etc sends a error only thru
http error 500, so I cant filter out my custom errors with your tool
it seams, do you concur ?

Atif Aziz

unread,
Jan 23, 2010, 3:04:37 PM1/23/10
to el...@googlegroups.com
When you say Err.Raise(-999, ...), are you talking in terms of Visual Basic?


--

Digs

unread,
Jan 23, 2010, 4:40:19 PM1/23/10
to ELMAH
YES I am...

Atif Aziz

unread,
Jan 23, 2010, 5:51:03 PM1/23/10
to el...@googlegroups.com
In that case...
 
However it seams that err.raise(-999, etc  sends a error only thru
http error 500
That's correct because a general server error usually gets takes the form of an HTTP 500 error.
 
, so I cant filter out my custom errors with your tool
it seams, do you concur ?
 
You can still do this. The problem is that the error number in Visual Basic is not available on the thrown exception object so you cannot filter by just relying on regular data-binding to the properties of the exception object. Instead the number is stored in Err.Number. This cannot be accessed through the simple filters so you'll have to go with one of the following two options instead: 
  1. Write a custom filter that checks against Err.Number
  2. Use the jscript filter supplied with ELMAH for corner and advanced cases
I don't think you have to go with 1 since 2 can be just done out of the box. Here's how you can setup that filter to ignore errors when Err.Number is less than zero:
 
<errorFilter>
  <test>
    <jscript>
      <expression>
      <![CDATA[
      // @assembly Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
      // @import Microsoft.VisualBasic
      Information.Err().Number < 0
      ]]>
      </expression>
    </jscript>
  </test>
</errorFilter>
 
- Atif
 
P.S. The @assembly line above may wrap due to reformatting of this post so make sure it's on a single line.
 
On Sat, Jan 23, 2010 at 10:40 PM, Digs <dig...@gmail.com> wrote:
 
YES I am...
 
--
 

Digs

unread,
Jan 23, 2010, 5:56:18 PM1/23/10
to ELMAH
Thanks ..with your javascript filter.. how do I make it an
'OR'..filter

with

Atif Aziz

unread,
Jan 23, 2010, 6:01:09 PM1/23/10
to el...@googlegroups.com
You can add to the JScript expression like this:
 
<errorFilter>
  <test>
    <jscript>
      <expression>
      <![CDATA[
      // @assembly Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
      // @import Microsoft.VisualBasic
      Information.Err().Number < 0
      || HttpStatusCode == 404
      ]]>
      </expression>
    </jscript>
  </test>
</errorFilter>
 
You can also do it as I showed you before with <or>:
 
<errorFilter>
  <test>
    <or>

      <equal binding="HttpStatusCode" value="404" type="Int32" />
      <jscript>
        <expression>
        <![CDATA[
        // @assembly Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
        // @import Microsoft.VisualBasic
        Information.Err().Number < 0
        ]]>
        </expression>
      </jscript>
    </or>
  </test>
</errorFilter>
 
- Atif

Digs

unread,
Jan 23, 2010, 6:05:44 PM1/23/10
to ELMAH
Thanks for help !
Reply all
Reply to author
Forward
0 new messages