Click here to Skip to main content
15,920,686 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: How about new syntactical sugar for exception checking? Pin
Jörgen Andersson21-Jul-16 10:09
professionalJörgen Andersson21-Jul-16 10:09 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Foothill21-Jul-16 10:55
professionalFoothill21-Jul-16 10:55 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Chris Maunder21-Jul-16 11:02
cofounderChris Maunder21-Jul-16 11:02 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Foothill21-Jul-16 11:08
professionalFoothill21-Jul-16 11:08 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Richard Deeming22-Jul-16 1:58
mveRichard Deeming22-Jul-16 1:58 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Joe Woodbury21-Jul-16 10:56
professionalJoe Woodbury21-Jul-16 10:56 
GeneralRe: How about new syntactical sugar for exception checking? Pin
PIEBALDconsult21-Jul-16 14:29
mvePIEBALDconsult21-Jul-16 14:29 
GeneralRe: How about new syntactical sugar for exception checking? Pin
BillWoodruff21-Jul-16 15:46
professionalBillWoodruff21-Jul-16 15:46 
You get my up-vote for the idea, but making the idea more general-purpose means, imho, not being able to use an Extension method with generics, since the 'this parameter of an Extension method cannot be declared 'ref, or 'out.

How about this (based on the code example in my previous reply to this thread)
C#
using System;

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

    public static class DodgyUtilities
    {
        public static DodgyResult TryGetValueFromDodgy<T1,T2>(T1 t1, ref T2 t2, Func<T1,T2> func)
        {
            try
            {
                t2 = func(t1);
    
                if (t2 == null)
                {
                    return DodgyResult.ResultNull;
                }
                else
                {
                    return DodgyResult.ResultOkay;
                }
            }
            catch (Exception)
            {
                return DodgyResult.ResultError;
            }
        }
    }
}

«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

GeneralRe: How about new syntactical sugar for exception checking? Pin
Roger Wright21-Jul-16 20:55
professionalRoger Wright21-Jul-16 20:55 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Duncan Edwards Jones21-Jul-16 21:09
professionalDuncan Edwards Jones21-Jul-16 21:09 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Dan Neely22-Jul-16 2:55
Dan Neely22-Jul-16 2:55 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Chris Maunder22-Jul-16 3:50
cofounderChris Maunder22-Jul-16 3:50 
GeneralRe: How about new syntactical sugar for exception checking? Pin
TheGreatAndPowerfulOz22-Jul-16 3:42
TheGreatAndPowerfulOz22-Jul-16 3:42 
GeneralRe: How about new syntactical sugar for exception checking? Pin
agolddog22-Jul-16 3:45
agolddog22-Jul-16 3:45 
GeneralRe: How about new syntactical sugar for exception checking? Pin
englebart22-Jul-16 4:29
professionalenglebart22-Jul-16 4:29 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Gerry Schmitz22-Jul-16 10:17
mveGerry Schmitz22-Jul-16 10:17 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Chris Maunder24-Jul-16 15:21
cofounderChris Maunder24-Jul-16 15:21 
GeneralRe: How about new syntactical sugar for exception checking? Pin
Kiriander25-Jul-16 2:10
Kiriander25-Jul-16 2:10 
GeneralMost hilarious computer article Pin
patbob21-Jul-16 6:57
patbob21-Jul-16 6:57 
GeneralRe: Most hilarious computer article Pin
Chris Maunder21-Jul-16 7:03
cofounderChris Maunder21-Jul-16 7:03 
GeneralRe: Most hilarious computer article Pin
RossMW21-Jul-16 10:20
professionalRossMW21-Jul-16 10:20 
GeneralRe: Most hilarious computer article Pin
Michael Martin21-Jul-16 17:01
professionalMichael Martin21-Jul-16 17:01 
GeneralRe: Most hilarious computer article Pin
Chris Maunder24-Jul-16 15:37
cofounderChris Maunder24-Jul-16 15:37 
GeneralRe: Most hilarious computer article Pin
Ravi Bhavnani21-Jul-16 7:32
professionalRavi Bhavnani21-Jul-16 7:32 
GeneralRe: Most hilarious computer article Pin
Roger Wright21-Jul-16 21:01
professionalRoger Wright21-Jul-16 21:01 

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.