Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8442911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:58:17+00:00 2026-06-10T08:58:17+00:00

I need to capture any exceptions thrown by the validator but I cannot figure

  • 0

I need to capture any exceptions thrown by the validator but I cannot figure out how to due it. Here is the code I have tried:

internal static class XMLValidator
{
    public static void Validate(XElement elem)
    {            
        string xsdMarkup;

        using(var file = new StreamReader(Constants.Xsd))
        {               
            xsdMarkup = file.ReadToEnd();
        }       

        XmlSchemaSet schema = new XmlSchemaSet();
        bool valid = true;
        schema.Add(XmlSchema.Read(XElement.Parse(xsdMarkup).CreateReader(), (o, e) => { }));
        new XDocument(elem).Validate(schema, (o, e) => { valid = false; exception = e; });
        if (valid == false)
        {
            throw exception;               
        }
        valid = true;                          
    }
}

I get a “the name exception does not exist in current context” error. I’m pretty sure that the problem is that I have not given exception a data type. However I have no idea what type to use.

I tried adding var before the exception but then it’s not recogonized inside of the if statement and of course var cannot be declared outside of a method

I then tried declaring exemption globally as a string and setting to e like this:

exception = e.ToString();

but then I can’t throw it inside of the if statement.

How would I go about doing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:58:19+00:00Added an answer on June 10, 2026 at 8:58 am

    The delegate you’re using creates an XmlSchemaValidationException:

        XmlSchemaValidationException exception = null;
        new XDocument(elem).Validate(schema, (o, e) => { valid = false; exception = e.Exception; });
        if (valid == false)
        {
            throw exception;               
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My problem is I need to capture a keypress but at any given time
I need to capture keystokes from a wedge device and prevent any controls or
I need to capture either \d+\.\d+ or \d+ but nothing else. For instance ,
We have a need to capture signatures from an iOS app – the use
I need to capture an Enter Key press at any time anywhere on a
I am having an page. I need to capture the exception which is thrown
Is there any good profiler which support Google App Engine? I need to capture
I need to capture the price out of the following string: Price: 30 .
I have a WinForm application where I need to capture a KeyPress and fetch
I have some HTML DOM elements for which I need to capture click events,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.