我的实时应用程序发生了崩溃,发生在以下代码中:
- (void)setUpProgressForAmount:(NSDecimalNumber*)amountValue forProgressView:(UIProgressView*)progressView overUnderLabel:(UILabel*)overUnderLabel forTextLabel:(UILabel*)textLabel {
__ENTERING_METHOD__
NSString *amountLeftString = nil;
NSDecimalNumber *amountLeftValue = [budgetedAmount decimalNumberBySubtracting:amountValue];
if ([amountLeftValue compare:[NSDecimalNumber zero]] == NSOrderedAscending) {
//make it a positive amount if a negative amount
amountLeftValue = [[NSDecimalNumber zero] decimalNumberBySubtracting: amountLeftValue];
}
amountLeftString = (NSString *)[[[ObjectsHelper sharedManager] currencyFormatter] stringFromNumber:amountLeftValue];
NSDecimalNumber *amountProgress;
NSString *overUnderString = nil;
if ([budgetedAmount compare:[NSDecimalNumber zero]] == NSOrderedDescending) {
[overUnderLabel setHidden:NO];
amountProgress = [amountValue decimalNumberByDividingBy:budgetedAmount];
[progressView setHidden:NO];
progressView.trackTintColor = [UIColor colorWithWhite:0 alpha:.05];
progressView.progress = [amountProgress doubleValue];
if ([amountProgress doubleValue] > 1.0) {
[progressView setProgressTintColor:[[MyTheme sharedTheme] defaultRedColor]];
overUnderString = [NSString stringWithFormat:@"%@ %@",amountLeftString,NSLocalizedString(@"over", @"over")];
[overUnderLabel setTextColor:[[MyTheme sharedTheme] defaultRedColor]];
}
else {
[progressView setProgressTintColor:[[MyTheme sharedTheme] defaultGreenColor]];
overUnderString = [NSString stringWithFormat:@"%@ %@",amountLeftString,NSLocalizedString(@"under", @"under")];
[overUnderLabel setTextColor:[[MyTheme sharedTheme] defaultGreenColor]];
}
overUnderLabel.text = overUnderString;
}
else {
[overUnderLabel setHidden:NO];
[overUnderLabel setText:@""];
[progressView setHidden:NO];
progressView.progress = 0;
}
}
它发生在以下行:
NSDecimalNumber *amountLeftValue = [budgetedAmount decimalNumberBySubtracting:amountValue];
崩溃的原因是:
*** Terminating app due to uncaught exception 'NSDecimalNumberOverflowException', reason: 'NSDecimalNumber overflow exception'
我之前从未见过这个错误,并且没有太多文档。至少到目前为止,我无法重现错误。
在代码中,budgetedAmount也是一个NSDecimalNumber,从这些方法之一的返回值设置(我不知道这次崩溃中的哪一个):
+ (NSDecimalNumber*)getBudgetAmountDecimalForBudgetAmountNumber:(NSNumber*)amtBudgetedInt canRound:(BOOL)canRound {
__ENTERING_METHOD__
NSDecimalNumber *budgetedAmountDecimalNumber = [NSDecimalNumber zero];
if([amtBudgetedInt integerValue] > 0){
budgetedAmountDecimalNumber = [NSDecimalNumber decimalNumberWithMantissa:[amtBudgetedInt integerValue] exponent:(0-[[[ObjectsHelper sharedManager] currencyScale] integerValue]) isNegative:NO];
if (canRound && [[[NSUserDefaults standardUserDefaults] objectForKey:kRoundAmounts] integerValue] != 0) { //not rounding (rounding is zero)
budgetedAmountDecimalNumber = [NSDecimalNumber decimalNumberWithString:[[[ObjectsHelper sharedManager] roundingFormatter] stringFromNumber:budgetedAmountDecimalNumber]];
}
}
return budgetedAmountDecimalNumber;
}
+ (NSArray*)getCalcBudgetAmountCanRound:(BOOL)canRound {
__ENTERING_METHOD__
NSDecimalNumber *calcBudgetedAmountDecimalNumber = [NSDecimalNumber zero];
NSInteger calcBudgetedAmountInt = 0;
for (Person *person in persons) {
NSNumber *personBudgetNumber = person.amtBudgetedInt;//NSNumber - numberWithInt
if ([personBudgetNumber integerValue] > 0) {
calcBudgetedAmountInt += [personBudgetNumber integerValue];
NSDecimalNumber *personBudget = [NSDecimalNumber decimalNumberWithMantissa:[personBudgetNumber integerValue] exponent:(0-[[[ObjectsHelper sharedManager] currencyScale] integerValue]) isNegative:NO];
if (canRound && [[[NSUserDefaults standardUserDefaults] objectForKey:kRoundAmounts] integerValue] != 0) {
calcBudgetedAmountDecimalNumber = [calcBudgetedAmountDecimalNumber decimalNumberByAdding:[NSDecimalNumber decimalNumberWithString:[[[ObjectsHelper sharedManager] roundingFormatter] stringFromNumber:personBudget]]];
}
else {
calcBudgetedAmountDecimalNumber = [calcBudgetedAmountDecimalNumber decimalNumberByAdding:personBudget];
}
}
}
}
NSNumber *calcBudgetedAmountNumber = [NSNumber numberWithInteger:calcBudgetedAmountInt];
return @[calcBudgetedAmountDecimalNumber,calcBudgetedAmountNumber];
}
我知道我可以调试这个,如果它发生在我自己的设备或模拟器上,但我无法从我拥有的数据中做到这一点,特别是因为我试图重现错误而不能
有人可以为我揭示这种情况,还是指出我正确的方向?感谢。
此处是崩溃报告的相关部分:
Exception Type: SIGABRT
Exception Codes: #0 at 0x38d331fc
Crashed Thread: 0
Application Specific Information:
*** Terminating app due to uncaught exception 'NSDecimalNumberOverflowException', reason: 'NSDecimalNumber overflow exception'
Last Exception Backtrace:
0 CoreFoundation 0x2e333f4b __exceptionPreprocess + 131
1 libobjc.A.dylib 0x387746af objc_exception_throw + 38
2 CoreFoundation 0x2e333e8d -[NSException initWithCoder:] + 0
3 Foundation 0x2ed2c6bd -[NSDecimalNumberHandler exceptionDuringOperation:error:leftOperand:rightOperand:] + 228
4 Foundation 0x2ed2b715 _checkErrorAndRound + 93
5 Foundation 0x2ed2b8a1 -[NSDecimalNumber decimalNumberBySubtracting:withBehavior:] + 116
6 MyApp 0x000b2cbb -[MyDetailViewController(Budget) setUpProgressForAmount:forProgressView:overUnderLabel:forTextLabel:] (MyDetailViewController+Budget.m:531)