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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. I can't get latest value by ref parameter. WHY? [modified]

I can't get latest value by ref parameter. WHY? [modified]

Scheduled Pinned Locked Moved C#
comdesignbusinessquestion
3 Posts 2 Posters 0 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.
  • C Offline
    C Offline
    codeadair
    wrote on last edited by
    #1

    There are two layers in my project. one is business layer,and the other is UI layer. In UI layer, i invoke the method 'SaveInfo' of business layer. by the way ServiceActivator.GetService. But i can't get 'newInfo' in UI layer. and if i remove 'throw ex;' in 'SaveInfo' method. i could get it. i don't know why. do you know? how could i get newInfo if i want to throw Exception to UI layer. pls. ths. 'SaveInfo' in Business layer: public void SaveInfo(ref StudentInfo info,ref List detailList,string strType) { try { ... info = newInfo; detailList = newDetailList; throw new MyException("Information already exist."); ... } catch(Exception ex) { throw ex; } } the invoke code in UI layer: try { ... mMyDs.SaveInfo(ref curInfo,ref curList,"Add"); ... ] catch(MyException mex) { textBox1.text = curInfo.Name; } catch(Exception ex) { }

    MSN:msnadair@hotmail.com Skype:skyadair

    modified on Tuesday, May 12, 2009 8:52 PM

    H 1 Reply Last reply
    0
    • C codeadair

      There are two layers in my project. one is business layer,and the other is UI layer. In UI layer, i invoke the method 'SaveInfo' of business layer. by the way ServiceActivator.GetService. But i can't get 'newInfo' in UI layer. and if i remove 'throw ex;' in 'SaveInfo' method. i could get it. i don't know why. do you know? how could i get newInfo if i want to throw Exception to UI layer. pls. ths. 'SaveInfo' in Business layer: public void SaveInfo(ref StudentInfo info,ref List detailList,string strType) { try { ... info = newInfo; detailList = newDetailList; throw new MyException("Information already exist."); ... } catch(Exception ex) { throw ex; } } the invoke code in UI layer: try { ... mMyDs.SaveInfo(ref curInfo,ref curList,"Add"); ... ] catch(MyException mex) { textBox1.text = curInfo.Name; } catch(Exception ex) { }

      MSN:msnadair@hotmail.com Skype:skyadair

      modified on Tuesday, May 12, 2009 8:52 PM

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      I have to say that returning to a calling process by throwing an exception is not the normal way to do it. It would be better to give SaveInfo() a return type of bool and instead of throw new MyException use return true;. Then in your calling code use

      if (mMyDs.SaveInfo(ref curInfo,ref curList,"Add"))
      {
          // do whatever you want if all is well
      }
      else
      {
          // do whatever you want when it goes bad. e.g. throw an exception
      }
      

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      C 1 Reply Last reply
      0
      • H Henry Minute

        I have to say that returning to a calling process by throwing an exception is not the normal way to do it. It would be better to give SaveInfo() a return type of bool and instead of throw new MyException use return true;. Then in your calling code use

        if (mMyDs.SaveInfo(ref curInfo,ref curList,"Add"))
        {
            // do whatever you want if all is well
        }
        else
        {
            // do whatever you want when it goes bad. e.g. throw an exception
        }
        

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        C Offline
        C Offline
        codeadair
        wrote on last edited by
        #3

        No,i can't. i need to do this. i should return the latest data from database if the info already exist. and the info may have different status, i should throw out the hint.

        MSN:msnadair@hotmail.com Skype:skyadair

        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