Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. How about new syntactical sugar for exception checking?

How about new syntactical sugar for exception checking?

Scheduled Pinned Locked Moved The Lounge
htmlcomjsonquestion
42 Posts 27 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Too much time on your hands?

    C Offline
    C Offline
    Chris Maunder
    wrote on last edited by
    #41

    ;)

    cheers Chris Maunder

    1 Reply Last reply
    0
    • C Chris Maunder

      We get a shiny new "?" operator that takes

      string result = null;
      if (field != null)
      {
      result = field.Value;
      }

      and converts this to

      string result = field?.Value

      So what about the case where we're handling a flaky API

      string result = null;
      try
      {
      result = DodgyApi.GetValue(); // may throw an exception
      }
      catch
      {
      result = null;
      }

      What would you suggest we do for that? What about a headasplode (*) operator

      string result = DodgyApi.GetValue*();

      where GetValue* will silently swallow the exception thrown by GetValue and return default. Or am I setting a new standard for lazy, shameful programming here this hot, lazy afternoon?

      cheers Chris Maunder

      K Offline
      K Offline
      Kiriander
      wrote on last edited by
      #42

      Swallowing excepsions is bad style. If the function throws different exceptions, there may be strong need to react to them differently.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups