Defining excepion
-
Hello, I just want to override the System.Exception in order to log when an exception occurrs in an XML file, for doing that I tought I sould declare a class called exception and then to do
public class Exception : System.Exception { .... }
but I don't know to say to code that I want to use my exception when I docatch (Exception ex) { .... }
thanks Paolo -
Hello, I just want to override the System.Exception in order to log when an exception occurrs in an XML file, for doing that I tought I sould declare a class called exception and then to do
public class Exception : System.Exception { .... }
but I don't know to say to code that I want to use my exception when I docatch (Exception ex) { .... }
thanks PaoloYou could do something like this:
namespace MyNamespace
{
public class Exception : System.Exception
{
}public class Foo
{
public void Bar()
{
try {}
catch (MyNamespace.Exception e) {}
}
}
}However, you really should not do it like this. Instead use a self-explanatory name for your exception class that ends with Exception (just as an example: XMLProcessingException). For details on using exceptions see Class Naming Guidelines[^], Best Practices for Handling Exceptions[^] and Using User-Defined Exceptions[^]. Best regards Dennis