Click here to Skip to main content
15,917,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Thanks for the previous help.

I call the following function and pass a string value "string8" which is not in the resuorce file already.then how come my following code is not throwing an exeption and show any message saying something like" its not found" any logic is wrong with my try catch?

C#
public void printmessage(string value)
{
   try
   {
      string x = (string)GetGlobalResourceObject(Resource1, value);
       Label1.Text = string.Format("{0}", x);
    }
    catch (Exception ex)
    {
       Response.Write(ex.ToString());
    }
}
Posted
Updated 13-Sep-11 8:45am
v2
Comments
Thiagarajan Duraisamy 13-Sep-11 15:08pm    
if your output says like GetGlobalResourceObject not found try qualifing tat with the httpcontext class. eg HttpContext.GetGlobalResourceObject()
or

if the msg was
A resource object with the specified classKey parameter was not found.
it should be an exception (if possible show me ur result page)

GetGlobalResourceObject:
it returns an object that represents the requested resource object otherwise, null if a resource object is not found or if a resource object is found but it does not have the requested property.
Thiagarajan Duraisamy 14-Sep-11 2:45am    
got any solution, pls update the solution.

Place a breakpoint on the first line inside the try
string x = ... (this one)
Then debug your application. If and when the application breaks on that line, check the values of Resource1 and value, then step to the next line and see if it breaks into the catch block or if it goes on the the Label text set line. Again check the values, now of x and ex depending on where the logic takes you. At that point you should have a better understanding of what your problem is.
 
Share this answer
 
Comments
rajh7 13-Sep-11 14:54pm    
Thanks
Sergey Alexandrovich Kryukov 13-Sep-11 16:49pm    
Sound advice, my 5.
--SA
fjdiewornncalwe 13-Sep-11 18:27pm    
Thank you
GetGlobalResourceObject:
it returns an object that represents the requested resource object otherwise, null if a resource object is not found or if a resource object is found but it does not have the requested property.
C#
string x = (string)GetGlobalResourceObject(Resource1, value);

so when you try to cast a null to a string its nothing.
so this will not be an exception like tat in file read, where it returns an exception if the file not found.

the only exception thrown by the GetGlobalResourceObject is MissingManifestResourceException which returns the string 'A resource object with the specified classKey parameter was not found'



if your output says like GetGlobalResourceObject not found try qualifing that with the httpcontext class. eg HttpContext.GetGlobalResourceObject()
 
Share this answer
 
v2
Comments
Simon Bang Terkildsen 14-Sep-11 0:59am    
Added code block and removed text speak
Thiagarajan Duraisamy 14-Sep-11 23:53pm    
i dont think this exception wil be thrown mostly, i asked my mentor.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900