something is not clear to me
i want to check if a specific February is a leap year with this piece of code:
so if the try wont be able to parse the date the catch should be raised and i should get a false returned
but i am getting an error and a crash that says could not parse the date.
but why does this code crash? i am using a try catch..
any clue?
regards, ilan
i want to check if a specific February is a leap year with this piece of code:
B4X:
Sub IsLeapYear(Year As Int) As Boolean
Try
DateTime.DateFormat = "MM/dd/yyyy"
DateTime.DateParse("02/29/" & Year)
Return True
Catch
Log(LastException)
Return False
End Try
End Sub
so if the try wont be able to parse the date the catch should be raised and i should get a false returned
but i am getting an error and a crash that says could not parse the date.
Copying updated assets files (227)
Application_Start
Between mdays: 01/08/2016 - 31/08/2016
Between mdays: 01/09/2016 - 30/09/2016
Between mdays: 01/10/2016 - 31/10/2016
Between mdays: 01/11/2016 - 30/11/2016
Between mdays: 01/12/2016 - 31/12/2016
Between mdays: 01/01/2017 - 31/01/2017
<B4IExceptionWrapper: Error Domain=caught_exception Code=0 "Error parsing: 02/29/2017" UserInfo={NSLocalizedDescription=Error parsing: 02/29/2017}>
Error occurred on line: 790 (Main)
Error parsing: 28/02/2017
Stack Trace: (
CoreFoundation <redacted> + 150
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
B4i Example -[B4IDateTime DateParse:] + 186
B4i Example -[b4i_main _updateclv] + 4400
B4i Example -[b4i_main _shiftdateright_click] + 1208
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 292
B4i Example +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1786
B4i Example -[B4IShell runMethod:] + 574
B4i Example -[B4IShell raiseEventImpl:method:args::] + 1998
B4i Example -[B4IShellBI raiseEvent:eventarams:] + 1442
B4i Example __33-[B4I raiseUIEvent:eventarams:]_block_invoke + 74
libdispatch.dylib <redacted> + 10
libdispatch.dylib <redacted> + 22
libdispatch.dylib <redacted> + 1524
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 1574
CoreFoundation CFRunLoopRunSpecific + 520
CoreFoundation CFRunLoopRunInMode + 108
GraphicsServices GSEventRunModal + 160
UIKit UIApplicationMain + 144
B4i Example main + 108
libdyld.dylib <redacted> + 2
)
but why does this code crash? i am using a try catch..
any clue?
regards, ilan