I faced problem as in title, when I call .toRelative(since:style:locale:) on my date which as string is f.e. "2022-06-07 13:12:06 +0000" my app crashes. Crash stack from Console app prints:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 SwiftDate 0x10425f4ee specialized static RelativeFormatter.suitableFlavour(inList:forLocale:) + 1230
1 SwiftDate 0x10425e46d specialized static RelativeFormatter.format(date:to:style:locale:) + 1517
2 SwiftDate 0x104252e9b DateRepresentable.toRelative(since:style:locale:) + 507
3 MyApp 0x103f8d8cf 0x103f76000 + 96463
The line where I call that is the last one below:
var locales = Locales.english
let style = RelativeFormatter.timeStyle()
return creationDate.toRelative(style:style, locale: locales)
Maybe is significant that I call that in SwiftUI.
The problem occurs after a few launches on OS X 10.15 and 12.4 at this moment, architecture x86_64.
The error is:
System Integrity Protection: enabled
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes: 0x0000000000000001, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: Namespace SIGNAL, Code 4 Illegal instruction: 4
Terminating Process: exc handler [830]
Thanks for every help!
Related
I have a crash log for my current iPhone app which is symbolicated, but I am having trouble deciphering what the problem is still.
The basic issue is that on certain devices (particularly older ones) my app with crash back to the home screen. It appears to be when a user comes back to my game after a while - which initiates a login process to the Game Center. I have pasted the relevant part of the crash log below:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x2e000000
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x37c11f7e objc_msgSend + 22
1 Transfer Quiz 0x000023c4 -[GameCenterManager callDelegate:withArg:error:] (GameCenterManager.m:113)
2 Transfer Quiz 0x0000230c __60-[GameCenterManager callDelegateOnMainThread:withArg:error:]_block_invoke_0 (GameCenterManager.m:103)
3 libdispatch.dylib 0x346fdc52 _dispatch_call_block_and_release + 6
4 libdispatch.dylib 0x346ffee0 _dispatch_main_queue_callback_4CF$VARIANT$mp + 188
5 CoreFoundation 0x358432a6 __CFRunLoopRun + 1262
6 CoreFoundation 0x357c649e CFRunLoopRunSpecific + 294
7 CoreFoundation 0x357c6366 CFRunLoopRunInMode + 98
8 GraphicsServices 0x37462432 GSEventRunModal + 130
9 UIKit 0x332d2cce UIApplicationMain + 1074
10 Transfer Quiz 0x000030d4 main (main.m:16)
11 Transfer Quiz 0x000021a8 start + 32
and here is the following code for GameCenterManager callDelegate:
- (void) callDelegate: (SEL) selector withArg: (id) arg error: (NSError*) err
{
assert([NSThread isMainThread]);
if([delegate respondsToSelector: selector])
{
if(arg != NULL)
{
[delegate performSelector: selector withObject: arg withObject: err];
}
else
{
[delegate performSelector: selector withObject: err];
}
}
else
{
NSLog(#"Missed Method");
}
}
The code was part of a tutorial on an external tutorial website - and I cannot pinpoint the issue that's causing my app to crash here.
Does anyone know of a reason why code is causing the crash? Any help would be much appreciated. I am finding it very hard to replicate the crash on any device and using NSZombies is also not working probably due to my inability to recreate the crash.
Thank you all, in advance.
It seems that the selector you're calling takes 2 arguments: an 'arg' and an 'error'. Now the thing is that if 'arg' is nil, you're calling the selector to one argument only - so the second argument is basically garbage, and when the object on which the selector is called tries to access the second argument, it crashes. All in all, you don't need that if() - always pass both arguments to the selector and let the delegate detect if its first argument is nil.
I have a problem in my code the app is crash with error
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[__NSCFDictionary
setObject:forKey:]: attempt to insert nil value (key: app_ver)'
* First throw call stack: (0x874022 0x257acd6 0x81ca48 0x81c9b9 0x8732da 0x8c473 0x8c119 0x7d803 0x7d74c 0x875e42 0x82670 0x13eda49
0x13ebe84 0x13ecea7 0x13ebe3f 0x13ebfc5 0x1330f5a 0x2f1ca39 0x2fe9596
0x2f13120 0x2fe9117 0x2f12fbf 0x84894f 0x7abb43 0x7ab424 0x7aad84
0x7aac9b 0x133040f 0x82a35 0x12fc4d6 0x12fc447 0x99595ed9 0x995996de)
terminate called throwing an exception
You try to insert a nil object. Test for it first.
if(anObject){
[myDictionary setValue:anObject forKey:kAnKey];
}
You are trying to set a dictionary object without any key (nil).
Check this for more details: setObject:ForKey: crash?
EDIT: Issue has been solved(partially):It is a simulator bug. I've compiled and tested this on two devices with iOS 3.1.3 and 4.0. The exception was handled correctly. Be careful, the simulator is your enemy!
this is driving me crazy. I don't know how to enable exception handling in my project. Look at the code and debugger output below.
My Goal is to catch the exception, not correcting the code so the exception is handled and the app doesn't crash.
I'm using XCode 3.2.3, iPhone SDK 4 final. I have just created a simple view based iPhone App to test this.
I have looked in my project settings and yes the switch "Enable Objective-C Exceptions" is checked. I am using GCC 4.2.
When I look at the build process in detail the compiler flag -fno-objc-exceptions is not within the list of arguments!
What am I missing here?
Thanks in advance
Nick
NSArray * foo = [[NSArray alloc] init];
#try {
NSLog(#"trying...");
[foo objectForKey:#"yeah"];
}
#catch (NSException * e) {
NSLog(#"catching %# reason %#", [e name], [e reason]);
}
#finally {
NSLog(#"finally");
}
leads to
trying...
-[__NSArrayI objectForKey:]: unrecognized selector sent to instance 0x5d5f780
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI objectForKey:]: unrecognized selector sent to instance 0x5d5f780'
*** Call stack at first throw:
(
0 CoreFoundation 0x02393919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x024e15de objc_exception_throw + 47
2 CoreFoundation 0x0239542b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x02305116 ___forwarding___ + 966
4 CoreFoundation 0x02304cd2 _CF_forwarding_prep_0 + 50
...
)
terminate called after throwing an instance of 'NSException'
Whether the catch nor the finally block is ever reached.
Quote from How do I catch global exceptions? :
"objc_exception_throw is not an exception. It is the function that throws Objective-C exceptions. Similarly, EXC_ARITHMETIC is not an Objective-C exception; it is a Mach (kernel) exception, meaning that your app tried to do something completely invalid. – Peter Hosey May 14 at 9:14"
That thread does have a link to a solution for your problem though, it appears. The link goes to http://www.restoroot.com/Blog/2008/10/20/crash-reporter-for-iphone-applications-part-2/ which looks a little risky, but if it works, it might be worth it for you.
There are bug reports related to this, e.g.: http://www.openradar.me/8081169 (posted earlier this month)
(Updated to summarize information from comments below.)
If I understand your problem right.
Your Try/ catch block is working correctly.
It is trying to run your code, and catches an error.
You need to decide what to do when it catches an error and code for it within the block.
I normally do that in the CATCH part. As the finally bit will execute regardless of an exception or not being thrown.
Your example code is catching the NSException exception but not the one being thrown, NSInvalidArgumentException. You might have better luck if you look for that specific exception.
NSArray * foo = [[NSArray alloc] init];
#try {
NSLog(#"trying...");
[foo objectForKey:#"yeah"];
}
#catch (NSInvalidArgumentException *e) {
NSLog(#"Invalid argument called.");
}
#catch (NSException * e) {
NSLog(#"catching %# reason %#", [e name], [e reason]);
}
#finally {
NSLog(#"finally");
}
I don't have any way of testing it myself right now, though.
See http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocExceptionHandling.html for more information.
I'm getting this exception in
[self.navigationcontroller PopViewControllerAnimated:YES];
2010-06-21 19:12:46.585 IChitMe[31250:207] *** -[NSKeyValueIvarSetter addSubview:]: unrecognized selector sent to instance 0x377010
2010-06-21 19:12:46.593 IChitMe[31250:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSKeyValueIvarSetter addSubview:]: unrecognized selector sent to instance 0x377010'
2010-06-21 19:12:46.604 IChitMe[31250:207] Stack: (
864992541,
859229716,
864996349,
864492313,
864454720,
805091,
795933,
839415824,
839414704,
839684408,
839683992,
1282379,
864749711,
839231364,
839683900,
864749711,
839231364,
839231212,
839231156,
839230220,
839233420,
839227648,
839225236,
839206800,
839205012,
875886564,
864740651,
864738335,
875880904,
838872112,
838865456,
10345,
10208
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
(gdb)
popViewControllerAnimated should start with lowercase p
That looks to me like a UIViewController or UIView has been over-released. You, or iOS, is trying to add a subview to a view, but the message is being sent to a NSKeyValueIvarSetter. In all likelihood, that's because the memory for the intended UIView has been reclaimed and reallocated.
I'm trying to use NSAssert throughout my iPhone app so that if an unexpected condition occurs, the application fails-fast and crashes with a meaningful message in the crash log.
This works fine if the failing NSAssert is on the main thread, as it raises NSInternalInconsistencyException by default which is uncaught and stops execution. But I'm also doing processing in background threads, in which case the NSAssert just aborts the thread, but the programming keeps running.
My current solution is to catch and rethrow the exception in the main thread (in this case, NSOperation's main method):
- (void)main {
#try {
int x = 14;
...
NSAssert1(x > 20, #"x should be greater than 20, was %d", x);
...
}
#catch (NSException *e) {
[e performSelectorOnMainThread:#selector(raise) withObject:nil waitUntilDone:YES];
}
}
Is there a better way? Perhaps using a custom NSAssertionHandler?
I know I could just use C's assert with a static annotation:
assert(x > 20 && "x should be greater than 20");
But this doesn't allow me to show what the actual failing value of x is.
You can replace the NSAssert with a test code followed by an exception raise. This way, if the assertion failed, an exception will be thrown, catched by the #catch block and re-raised on the main thread.
Note: You can even define a C macro, in order to provide a compact form.