Click here to Skip to main content
15,921,793 members
Home / Discussions / C#
   

C#

 
GeneralRe: Datatable to Excel Pin
Chris Quinn13-Jan-17 5:07
Chris Quinn13-Jan-17 5:07 
GeneralRe: Datatable to Excel Pin
theoldfool14-Jan-17 16:16
professionaltheoldfool14-Jan-17 16:16 
GeneralRe: Datatable to Excel Pin
Dave Kreskowiak14-Jan-17 16:45
mveDave Kreskowiak14-Jan-17 16:45 
GeneralRe: Datatable to Excel Pin
theoldfool15-Jan-17 2:21
professionaltheoldfool15-Jan-17 2:21 
AnswerRe: Datatable to Excel Pin
Brisingr Aerowing12-Jan-17 12:26
professionalBrisingr Aerowing12-Jan-17 12:26 
QuestionHow to Use Telerik Split button Pin
Member 1293879712-Jan-17 6:38
Member 1293879712-Jan-17 6:38 
AnswerRe: How to Use Telerik Split button Pin
NotPolitcallyCorrect12-Jan-17 8:03
NotPolitcallyCorrect12-Jan-17 8:03 
GeneralRe: How to Use Telerik Split button Pin
Member 1293879713-Jan-17 7:50
Member 1293879713-Jan-17 7:50 
GeneralRe: How to Use Telerik Split button Pin
NotPolitcallyCorrect13-Jan-17 8:25
NotPolitcallyCorrect13-Jan-17 8:25 
GeneralRe: How to Use Telerik Split button Pin
Graeme_Grant15-Jan-17 0:26
mvaGraeme_Grant15-Jan-17 0:26 
QuestionFingerprint and mysql database Pin
King_Eke11-Jan-17 11:26
King_Eke11-Jan-17 11:26 
AnswerRe: Fingerprint and mysql database Pin
Gerry Schmitz11-Jan-17 17:00
mveGerry Schmitz11-Jan-17 17:00 
AnswerRe: Fingerprint and mysql database Pin
Afzaal Ahmad Zeeshan11-Jan-17 23:17
professionalAfzaal Ahmad Zeeshan11-Jan-17 23:17 
QuestionCustom Exceptions - Best Practices Pin
JBHowl11-Jan-17 9:23
JBHowl11-Jan-17 9:23 
AnswerRe: Custom Exceptions - Best Practices Pin
Pete O'Hanlon11-Jan-17 11:48
mvePete O'Hanlon11-Jan-17 11:48 
AnswerRe: Custom Exceptions - Best Practices Pin
Gerry Schmitz11-Jan-17 16:55
mveGerry Schmitz11-Jan-17 16:55 
AnswerRe: Custom Exceptions - Best Practices Pin
Richard Deeming12-Jan-17 6:54
mveRichard Deeming12-Jan-17 6:54 
For any real exception, you'll need to make it serializable.

You should also have a constructor which accepts the inner exception, if there is one.
C#
[Serializable]
public class AccessIOPortException : Exception
{
    public AccessIOPortException(string message, int port, Exception innerException) : base(FormatMessage(message, port), innerException)
    {
        Port = port;
    }
    
    public AccessIOPortException(string message, int port) : base(FormatMessage(message, port))
    {
        Port = port;
    }
    
    protected AccessIOPortException(SerializationInfo info, StreamingContext context) : base(info, context)
    {
        Port = info.GetInt32(nameof(Port));
    }
    
    [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
    public override void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        base.GetObjectData(info, context);
        info.AddValue(nameof(Port), Port);
    }
    
    private static string FormatMessage(string message, int port)
    {
        // TODO: Load from a resource file for localization:
        return $"Error while accessing IO port {port}\n{message}";
    }
    
    public int Port { get; }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Custom Exceptions - Best Practices Pin
BillWoodruff22-Jan-17 15:10
professionalBillWoodruff22-Jan-17 15:10 
QuestionC# classes Pin
Bobbla1310-Jan-17 23:17
Bobbla1310-Jan-17 23:17 
GeneralRe: C# classes Pin
harold aptroot10-Jan-17 23:35
harold aptroot10-Jan-17 23:35 
GeneralRe: C# classes Pin
#realJSOP11-Jan-17 7:47
professional#realJSOP11-Jan-17 7:47 
GeneralRe: C# classes Pin
OriginalGriff11-Jan-17 8:03
mveOriginalGriff11-Jan-17 8:03 
GeneralRe: C# classes Pin
#realJSOP12-Jan-17 2:06
professional#realJSOP12-Jan-17 2:06 
AnswerRe: C# classes Pin
Daniel Pfeffer10-Jan-17 23:36
professionalDaniel Pfeffer10-Jan-17 23:36 
AnswerRe: C# classes Pin
Pete O'Hanlon10-Jan-17 23:43
mvePete O'Hanlon10-Jan-17 23:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.