C# and custom errors.

Started by
3 comments, last by SiCrane 18 years, 3 months ago
I know there is an option to create my own errors in c++. I'd like to know if it can be done also in c#. [smile]
Advertisement
I've always created them by creating a custom class that's derived from the System.ApplicationException class, and then using the command:
"throw new custom_error_name()"

Dave
public class MyError : System.Exception {  MyError() : base( "Unspecified error" ) {}  MyError( string n ) : base( n ) {}  MyError( string n, System.Exception inner ) : base( n, inner ) {}}

enum Bool { True, False, FileNotFound };
I was talking of errors in compilation time :)
You can use #error in C#, though it tends to be less useful than in C++.

This topic is closed to new replies.

Advertisement