Click here to Skip to main content
15,902,032 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Well then... Pin
TheGreatAndPowerfulOz21-Jul-16 11:20
TheGreatAndPowerfulOz21-Jul-16 11:20 
GeneralHow about new syntactical sugar for exception checking? Pin
Chris Maunder21-Jul-16 6:58
cofounderChris Maunder21-Jul-16 6:58 
GeneralRe: How about new syntactical sugar for exception checking? PinPopular
Richard Deeming21-Jul-16 7:13
mveRichard Deeming21-Jul-16 7:13 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Ryan Peden21-Jul-16 9:08
professionalRyan Peden21-Jul-16 9:08 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Richard Deeming21-Jul-16 9:20
mveRichard Deeming21-Jul-16 9:20 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Ryan Peden21-Jul-16 9:28
professionalRyan Peden21-Jul-16 9:28 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Richard Deeming21-Jul-16 9:51
mveRichard Deeming21-Jul-16 9:51 
GeneralRe: How about new syntactical sugar for exception checking? Pin
BillWoodruff21-Jul-16 13:54
professionalBillWoodruff21-Jul-16 13:54 
C#
using System;

namespace InMemoriamMaunder
{
    public enum DodgyResult
    {
        ResultNull,
        ResultNonNull,
        ResultError
    }

    public static class Dodgy
    {
        public static DodgyResult RunDodgy<T>(ref T param, Func<T, T> dodgyFunc)
        {
            try
            {
                param = dodgyFunc(param);

                if (param == null)
                {
                    return DodgyResult.ResultNull;
                }
                else
                {
                    return DodgyResult.ResultOkay;
                }
            }
            catch (Exception)
            {
                 return DodgyResult.ResultError;
            }
        }
    }
}
Tests:
C#
private string SomeFuncError(string astring)
{
    astring = null;
    return astring.ToString();
}

private string SomeFuncNull(string astring)
{
    astring = null;
    return astring;
}

private string SomeFuncOkay(string astring)
{
    astring = astring + astring;
    return astring;
}
C#
string astring1 = "hello";
string astring2 = null;
string astring3 = "whatever";

DodgyResult dr1 = Dodgy.RunDodgy<string>(ref astring1, SomeFuncOkay);
DodgyResult dr2 = Dodgy.RunDodgy<string>(ref astring2, SomeFuncNull);
DodgyResult dr3 = Dodgy.RunDodgy<string>(ref astring3, SomeFuncError);
Now, Chris, all you have left to do is boil this down to a single operator Smile | :)
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008


modified 21-Jul-16 20:11pm.

GeneralRe: How about new syntactical sugar for exception checking? Pin
Richard Deeming22-Jul-16 2:24
mveRichard Deeming22-Jul-16 2:24 
GeneralRe: How about new syntactical sugar for exception checking? Pin
BillWoodruff24-Jul-16 14:58
professionalBillWoodruff24-Jul-16 14:58 
GeneralRe: How about new syntactical sugar for exception checking? Pin
#realJSOP21-Jul-16 7:19
professional#realJSOP21-Jul-16 7:19 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Corporal Agarn21-Jul-16 7:27
professionalCorporal Agarn21-Jul-16 7:27 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Sander Rossel21-Jul-16 20:42
professionalSander Rossel21-Jul-16 20:42 
GeneralRe: How about new syntactical sugar for exception checking? Pin
#realJSOP21-Jul-16 23:36
professional#realJSOP21-Jul-16 23:36 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Eddy Vluggen21-Jul-16 7:46
professionalEddy Vluggen21-Jul-16 7:46 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Chris Maunder21-Jul-16 8:09
cofounderChris Maunder21-Jul-16 8:09 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Gary Wheeler22-Jul-16 1:05
Gary Wheeler22-Jul-16 1:05 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Vark11121-Jul-16 7:47
Vark11121-Jul-16 7:47 
GeneralRe: How about new syntactical sugar for exception checking? Pin
OriginalGriff21-Jul-16 8:02
mveOriginalGriff21-Jul-16 8:02 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Nish Nishant21-Jul-16 8:13
sitebuilderNish Nishant21-Jul-16 8:13 
GeneralRe: How about new syntactical sugar for exception checking? Pin
CPallini21-Jul-16 21:18
mveCPallini21-Jul-16 21:18 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Harley L. Pebley22-Jul-16 8:52
Harley L. Pebley22-Jul-16 8:52 
GeneralRe: How about new syntactical sugar for exception checking? Pin
BillWoodruff24-Jul-16 15:16
professionalBillWoodruff24-Jul-16 15:16 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Kornfeld Eliyahu Peter21-Jul-16 8:29
professionalKornfeld Eliyahu Peter21-Jul-16 8:29 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Brisingr Aerowing21-Jul-16 9:59
professionalBrisingr Aerowing21-Jul-16 9:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.