Upgrade to Pro — share decks privately, control downloads, hide ads and more …

致命傷を避けるための例外実例集

 致命傷を避けるための例外実例集

Keishin Yokomaku

November 09, 2016
Tweet

More Decks by Keishin Yokomaku

Other Decks in Technology

Transcript

  1. க໋ইΛආ͚ΔͨΊͷྫ֎࣮ྫू About Me ▸ Keishin Yokomaku ▸ Drivemode, Inc. /

    Principal Engineer ▸ KeithYokoma: GitHub / Twitter / Qiita / Tumblr / Stack Overflow ▸ Books: Mobile App Dev Guide / Android Academia / Grimoire of Android ▸ Fun: Gymnastics / Cycling / Photography / Motorsport ▸ Today’s Quote: “࣌୅͸ے೑” 2
  2. 4

  3. க໋ইΛආ͚ΔͨΊͷྫ֎࣮ྫू ই͸ઙ͍͏ͪʹ࠹͙ ▸ ϦϦʔεઓུͱΫϥογϡݕ஌ͷ࢓૊Έ͸ඞਢςΫχοΫ ▸ Fabric(Crashlytics) ͰΫϥογϡϩάͷऩू ▸ Google Play

    Developer Console Ͱஈ֊తϦϦʔε ▸ ϢʔβϑΟʔυόοΫͷมԽʹؾ෇͘ ▸ ʮ࠷ۙ͜ΜͳϑΟʔυόοΫ͕Α͘དྷͯΔʯ ▸ ʮ͋ͷϑΟʔυόοΫݮͬͨʯ 6
  4. க໋ইΛආ͚ΔͨΊͷྫ֎࣮ྫू Let’s get started! ▸ ຊ೔ͷྫ֎Ϩγϐ ▸ ༗໊Ͳ͜Ζ͔ΒͲϚΠφʔͳ΋ͷ·ͰϞϦϞϦίʔε 8 NullPointerException

    OutOfMemoryError StackOverflowError Illegal**Exception CursorWindowAllocationException TransactionTooLargeException DeadObjectException
  5. க໋ইΛආ͚ΔͨΊͷྫ֎࣮ྫू NullPointerException ▸ ରࡦͷํ๏ ▸ ઃܭʹΑΔରࡦ ▸ ϝιου͕ null Λڐ༰͢Δ͔Ͳ͏͔ද໌͢Δ͜ͱͰɺ


    ୭͕null νΣοΫͷ੹຿Λෛ͏͔ܾΊΔ ▸ NullObject ύλʔϯΛ࢖ͬͯɺԿ΋ى͖ͳ͍Α͏ʹ޻෉͢Δ 12
  6. க໋ইΛආ͚ΔͨΊͷྫ֎࣮ྫू NullPointerException ▸ ରࡦͷํ๏ ▸ ϑϨʔϜϫʔΫͷίʔυͷ೺Ѳ ▸ Ͳ͏͍͏ঢ়گͰϝιου͕ null Λฦ͔͢஌͓ͬͯ͘

    ▸ Support Library ͷ࣮ଶΛ஌͓ͬͯ͘ ▸ ۭ࣮૷ͷ··ϦϦʔε͞Ε͍ͯΔ͕࣌͋Δ ▸ ϑϨʔϜϫʔΫͷ࡞๏ʹ४ͨ͡࡞ΓํΛ֮͑Δ 13
  7. க໋ইΛආ͚ΔͨΊͷྫ֎࣮ྫू StackOverflowError ▸ ελοΫΛ࢖͍௵ͨ͠ͱ͖ʹى͖Δྫ֎ ▸ e.g. ແݶ࠶ؼݺͼग़͠ ▸ ݟམͱ͕ͪ͠ͳՕॴ ▸

    ਂ͗͢ΔϨΠΞ΢τͷωετ: ϨΠΞ΢τ΋݁ہ͸ Java ͷΦϒδΣΫτʹͳΔ ▸ ਂ͗͢Δґଘؔ܎: ա৒ͳϨΠϠԽͰϝιουͷίʔϧελοΫʹݶք͕͘Δ 17
  8. க໋ইΛආ͚ΔͨΊͷྫ֎࣮ྫू StackOverflowError ▸ ରࡦํ๏ ▸ ϨΠΞ΢τͷ֊૚ߏ଄ΛݮΒ͢ ▸ RelativeLayout ΍ ConstraintLayout

    ͳͲͰϑϥοτͳߏ଄ʹ͢Δ ▸ ద੾ͳཻ౓ͰઃܭΛ͢Δ ▸ Clean Architecture ΍ DDD ͳͲΛࢀߟʹ 18
  9. க໋ইΛආ͚ΔͨΊͷྫ֎࣮ྫू Illegal**Exception ▸ छྨ͸৭ʑ ▸ IllegalStateException, IllegalArgumentException, etc… ▸ ݺͼग़͞ΕΔଆ͕૝ఆ͍ͯ͠ͳ͍ঢ়ଶɾҾ਺ʹ௚໘ͨ͠ͱ͖ʹى͖Δ

    ▸ ݺͼग़͢ଆ͕Ҿ਺νΣοΫ΍ঢ়ଶνΣοΫΛ͢Δ͜ͱΛཁٻ͍ͯ͠Δ ▸ ୺຤ґଘͰެࣜͷ Javadoc ʹॻ͍ͯͳ͍ͱ͖ʹඈΜͰ͘Δ͜ͱ͕͋Δ ▸ ո͍͠ͳʁͱࢥͬͨΒ͙͢ʹঢ়ଶ΍Ҿ਺ΛϩάʹͭΊͯूΊΒΕΔ࢓૊ΈΛ 20
  10. க໋ইΛආ͚ΔͨΊͷྫ֎࣮ྫू CursorWindowAllocationException ▸ σʔλϕʔεΛѻ͏ͱ໨ʹ͢Δྫ֎ ▸ Cursor ͕΋ͭσʔλ͕ڐ༰ൣғΛ௒͑ͨͱ͖ʹى͖Δ ▸ ϦϑΝϨϯεʹ Javadoc

    ͕ແ͍ྫ֎͕ͩɺࡶʹ࡞Δͱ໨ܸ͢Δϋϝʹ ▸ CursorWindow ΫϥεͷதͰϋϯυϦϯά͍ͯ͠Δ ▸ CursorWindow.java: http://bit.ly/2eKlL5y 23
  11. க໋ইΛආ͚ΔͨΊͷྫ֎࣮ྫू TransactionTooLargeException ▸ Intent ͷ extra ʹ 1mB Λ௒͑Δ String

    Λ౉͢͜ͱͰ΋ى͖Δఔ౓ʹ͸਎ۙͳͱ ͜ΖʹՄೳੑ͕͋Δ ▸ ରࡦํ๏ ▸ ڊେͳσʔλΛ௚઀ѻΘͳ͍ ▸ ϓϩηεؒ௨৴ͷ࣌ؒΛ୹͘͢Δ ▸ ϓϩηεؒ௨৴ͷճ਺ͦͷ΋ͷΛݮΒ͢ 27
  12. 31