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 3753360
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:22:50+00:00 2026-05-19T09:22:50+00:00

1) I have created a test exception. public class TestException : Exception { string

  • 0

1) I have created a test exception.

public class TestException : Exception
{
    string info;
    public string Info { get { return info; } set { info = value; } }
    public TestException() { }
    public TestException(string message) : base(message) { }
    public TestException(string message, Exception inner) : base(message, inner) { }
    protected TestException(
      System.Runtime.Serialization.SerializationInfo info,
      System.Runtime.Serialization.StreamingContext context)
        : base(info, context) { }
}

2) In a function somewhere in the website i got something like this:

catch (Exception e)
{
    TestException myOwnException = new TestException(e);
    myOwnException.Info = "test";
    LogError(myOwnException);
}

However i can’t cast from the base exception to my class. The logError expects a TestException.

I tried creating this inside my Exception class (Would allow me to write TestException myOwnException = e;)

public static implicit operator TestException(Exception e)
{
    return new TestException(e);
}

But i just keep getting:
user-defined conversions to or from a base class are not allowed.

How can i cast the exception from the catch statement into my TestException class? (I have also tried TestException test = (TestException)e; but that just returns an error.

  • 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-05-19T09:22:51+00:00Added an answer on May 19, 2026 at 9:22 am

    I’ll keep this short, you just cannot make this work. You’ll need to change the LogError() method to accept an Exception object. If any additional state is required (like Info) then add that as an argument to the LogError() method. Or make an overload.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement a sorted list. I have created the class I
I am trying to encode a simple String test back and forth. public static
I have created a web system using Java Servlets and now want to make
I have a xib-file with a small UIView on it, which in turn contains
I have a erratic problem with Java JMS. For moments works fine, but throws
Possible Duplicate: file_put_contents permission denied I have recently transferred server, and it seems that
tl;dr version: Is there a way to force a strict mode for JAX-WS that
I am currently working on an inherited codebase. One of the critical missing pieces
In IntelliJ 10.0.3 I use the menu option new web service and this generates
I encountered a strange issue while coding a .dll file in C with gcc

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.