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
S

spotsknight

@spotsknight
About
Posts
4
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • See the writing on the wall...
    S spotsknight

    Thank you! I didn't realize you could check the type of an object like that. Like I said I'm pretty much self taught and appreciate all suggestions to improve my code. One more question. Another thing I used the try/catch blocks for was to stop running code and display a custom error. For example if a company already existed in the database I'd set a custom message and throw an exception. Is that still a valid use of that or would it be better to build the code within the if statements. i.e. after removing the extra try/catch blocks so now I only have one within the function, would I use;

    if (tmpobj is int)
    {
    msg = "Company already has a project assigned";
    throw new Exception();
    }

    Then in the catch I display the msg. or instead would I use;

    if (tmpobj is int)
    msg = "Company already has a project assigned";
    else
    {
    //the rest of my code
    }
    MessageBox.Show(msg);

    The Weird and The Wonderful help learning sales json question

  • See the writing on the wall...
    S spotsknight

    Yes that is exactly what I am doing. I'm using the try/catch to handle the null reference exception that is thrown if there is no value. Is there a better way to do it?

    The Weird and The Wonderful help learning sales json question

  • See the writing on the wall...
    S spotsknight

    ok, this makes me question some of my code. I am pretty much self taught and don't have a lot of resources available other than online and within the help features. I comment quite a bit and try to use easy to understand variables (because otherwise a few months down the road when I need to add an update, I need to look back and know what I was doing). However, I do use empty catch blocks fairly often. Typically what I will do is set a variable to a default, then use a DB query to populate the variable with in a try/catch block (if the query returns no record it throws an exception). Then after the catch block, I'll check if the variable is the default value or not and execute code accordingly. Is there a better way or a standard practice that would be better? (see my sample snippet below, I use the prefix lowercase L to indicate the scope of variables that I reuse often)NOTE: This is a Windows Form app not a web site

                int HCID = -1;
                try
                {
                    lSQL = "Select HCID from HistoricalConversion where CoNum = '" + HCCoNum.Text + "'";
                    lAccessCmd.CommandText = lSQL;
                    HCID = (int)lAccessCmd.ExecuteScalar();
                }
                catch (Exception ex)
                {//Ignore error if no record exists
                }
    
                //Only run this code if there is an active historical conversion for this company
                if (HCID > 0) 
                {
                   //My code to run a stored Procedure if the record exists
                }
    
    The Weird and The Wonderful help learning sales json question

  • Are there reasons for beginner programmers to learn C ?
    S spotsknight

    I had some initial introduction to Basic in high school - way back in trash-80 (TRS-80) days. But my first and I feel MOST beneficial college class I EVER took was programming logic with pseudo-code and flow charting. After that my first language was C then later C++. If I had tried to learn C++ first I'm not sure I would have understood what was actually happening. When I'm writing code I want to make sure I understand what exact is happening. There is a lot in C++ that was much easier to learn knowing the basic C language.

    The Lounge learning c++ oop performance
  • Login

  • Don't have an account? Register

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