Year, Month, and Day parameters describe an un-representable DateTime

  • imgodot 2 months, 1 week ago

    I have a bound column in a Spread grid defined as DateTime.
    The column is defined as using the short format and the dates display properly in the grid as “mm/dd/yyyy”.

    However, when I am editing a date and press backspace so that I remove all the month digits or all the day digits I get a first chance exception,
    “Year, Month, and Day parameters describe an un-representable DateTime”.

    How do I prevent these errors?

    Thanks.
    – Paul

  • 50p
    Deepak Sharma50p 2 months, 1 week ago

    Hi Paul,

    I am not able to replicate this issue at my end. When I delete the month/day using backspace key it shows the default minimum day/month instead of 0 or any exception. Please refer to the attached sample application.

    Could you please provide me your sample application to debug this issue?

    Regards,
    Deepak Sharma

    Attachments:
    You must be logged in to view attched files.
  • imgodot 2 months ago

    Deepak,

    You can replicate the first chance exception in YOUR sample project, as I did.
    Turn on all exceptions in Visual Studio, test the issue and you will get this:

    A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
    Additional information: Year, Month, and Day parameters describe an un-representable DateTime.

    Thanks.
    – Paul

  • seanlawyer 2 months ago

    Hi Paul,

    If you turn on all exceptions in Visual Studio, you’re going to get a lot of noise from expected exceptions that are handled in various bits of code, and it sounds like this is the case here. Internal code uses DateTime.Parse to check whether the value in the cell is a valid DateTime and catch the expected InvalidOperationException when it isn’t. After the first-chance exception, the internal exception handler should get the exception and handle it normally.

    For more details about first-chance exceptions, please see here. Sometimes it’s useful to enable some particular exceptions for tracking down exactly where some issue comes from, but generally it isn’t a good idea and just makes the debug process slower.

    Regards,
    -Sean

  • imgodot 2 months ago

    Sean,

    I do understand that having all exceptions turned on leads to:
    A) FirstChanceExceptions that can be ignored (some, not ALL), and
    B) “Real” exceptions that should be coded for.

    However, we do not want to turn off exceptions so that we never see them.
    We have very stringent company-wide policies about that.

    I added a firstchanceexception handler to our app that will silently notify us via the console when a firstchance exception occurs while we are debugging our app.

    However, this “un-representable DateTime” exception is NOT trapped by the firstchance handler and is still thrown in our face; I don’t know why.
    We certainly don’t want to turn off ArgumentOutOfRange exceptions.

    Any other ideas on avoiding these ArgumentOutOfRange exceptions?

    Thanks.
    – Paul

  • 50p
    Deepak Sharma50p 2 months ago

    Hi Paul,

    I am able to replicate this issue at my end. I turn all the exceptions on and it makes the debugging very slow.
    However adding a handler for FirstChanceException seems to be handling the exception for me and silently shows it in the output window.
    Please check the attached sample application.

    Regards,
    Deepak Sharma

    Attachments:
    You must be logged in to view attched files.
  • imgodot 2 months ago

    Deepak,

    Thanks for the info.
    It led me in the right direction.

    I think we may decide to keep “Just my code” turned on in the debugger to prevent these types of first-chance exceptions.

    – Paul

  • 50p
    Deepak Sharma50p 2 months ago

    Hi Paul,

    Yes, in my sample application I checked the option for “Enable Just My Code” to hide non-user code so when you step, the debugger steps through any non-user code but does not stop in it.

    Glad that it helped you.

    Regards,
    Deepak Sharma

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to create new topics.