NSRange exception et crash

Ludopac

Membre actif
5 Avril 2001
970
4
42
Nancy
www.objectifmac.com
J’ai un problème dans mon application, j’utilise NSRange pour extraire une partie d’un NSString. Or si jamais le texte dans le NSString est un peu différent de ce que y est prévu, les NSRange que je demande peut-être un peu trop grand. Dans ce cas, il y a une exception NSRangeException et mon programme plante (quitte inopinément).

Y’a t’il un moyen de contourner cet crash ? Un truc comme il y en existe en Java du genre try { } catch(##Exception exep) { } ?
Je voudrais eu l’erreur soit ignoré et que le programme continue de tourner .

Merci d’avance ....
 
J'ai essayé et ça semble fonctionner
smile.gif


En tout cas ça ne plante plus depuis ...

Merci beaucoup
cool.gif
 
Une autre façon de faire c'est de consulter la liste des exception qu'il est possible de lever ici :

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/TypesAndConstants/FoundationTypes.html#//apple_ref/doc/uid/20000018/CJBCBDGD

dans la rubrique General Exception Names.

Pour ton cas c'est l'execption :

NSRangeException

tu dois faire donc :

if (condition) {
cas ou ca marche
} else {
[NSException raise:NSRangeException
format:mad:"Message d'erreur"];
}

Regarde la classe NSException.
 
Quand je démarre iMovie 11, j ai un message d'erreur interne:eek:
je vais dans afficher les détails et voila ce qu'il y a écrit :
Nom de l’exception*: NSRangeException
Description*: NSRLEArray objectAtIndex:effectiveRange:: Out of bounds
Informations sur l’utilisateur*: (null)

0 CoreFoundation 0x96cf2927 __raiseError + 231
1 libobjc.A.dylib 0x9116903d objc_exception_throw + 155
2 CoreFoundation 0x96cf2709 +[NSException raise:format:arguments:] + 137
3 CoreFoundation 0x96cf2679 +[NSException raise:format:] + 57
4 Foundation 0x958a1fda -[NSRLEArray objectAtIndex:effectiveRange:] + 115
5 Foundation 0x958a749c -[NSConcreteAttributedString attribute:atIndex:effectiveRange:] + 56
6 iMovie 0x002a4b5b iMovie + 2767707
7 iMovie 0x00137e42 iMovie + 1273410
8 iMovie 0x00136bfb iMovie + 1268731
9 iMovie 0x00135621 iMovie + 1263137
10 iMovie 0x0020901c iMovie + 2129948
11 iMovie 0x00239866 iMovie + 2328678
12 AppKit 0x940cbf1f -[NSView _drawRect:clip:] + 3691
13 AppKit 0x940caa54 -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 1923
14 AppKit 0x940c8c2b -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 708
15 AppKit 0x940c9d74 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5133
16 AppKit 0x940c9d74 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5133
17 AppKit 0x940c9d74 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5133
18 AppKit 0x940c9d74 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5133
19 AppKit 0x940c9d74 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5133
20 AppKit 0x940c9d74 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5133
21 AppKit 0x940c9d74 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5133
22 AppKit 0x940c9d74 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5133
23 AppKit 0x940c9d74 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5133
24 AppKit 0x940c9d74 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5133
25 AppKit 0x940c9d74 -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 5133
26 AppKit 0x94161e30 -[NSNextStepFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 286
27 AppKit 0x940c50a5 -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] + 3647
28 AppKit 0x94028b21 -[NSView displayIfNeeded] + 827
29 AppKit 0x93fdc3ff -[NSNextStepFrame displayIfNeeded] + 91
30 AppKit 0x93ff280d -[NSWindow displayIfNeeded] + 237
31 AppKit 0x946934c2 _handleWindowNeedsDisplayOrLayoutOrUpdateConstraints + 804
32 CoreFoundation 0x96d246cd _runLoopObserverWithBlockContext + 29
33 CoreFoundation 0x96d245de __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
34 CoreFoundation 0x96ca455d __CFRunLoopDoObservers + 413
35 CoreFoundation 0x96c65644 __CFRunLoopRun + 1044
36 CoreFoundation 0x96c64e1c CFRunLoopRunSpecific + 332
37 CoreFoundation 0x96c64cc8 CFRunLoopRunInMode + 120
38 HIToolbox 0x98af0c4b RunCurrentEventLoopInMode + 318
39 HIToolbox 0x98af093e ReceiveNextEventCommon + 168
40 HIToolbox 0x98af0882 BlockUntilNextEventMatchingListInMode + 88
41 AppKit 0x93ffa682 _DPSNextEvent + 678
42 AppKit 0x93ff9eee -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 113
43 iMovie 0x0004174d iMovie + 264013
44 AppKit 0x93fbbdec -[NSApplication run] + 897
45 AppKit 0x93fb3f2f NSApplicationMain + 1047
46 iMovie 0x0000326c iMovie + 8812
47 iMovie 0x00002a2e iMovie + 6702