Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can i set return so it accepts class1 or class2?
    primarykey
    data
    text
    <p>how can i, in my function start to fill the parameters for the class it is supposed to return, but if an exception occurs i'll return my error class instead?</p> <pre><code>public **** function() { try { Articles articles = new Articles(); articles.articleid = 234; articles.articlename = "Milk"; articles.deleted = 0; //continue fill Articles //and an exception occurs return articles; } catch (Exception e) { Errors Error = new Errors(); Error.exceptionmessage = e.Message; Error.exceptionname = e.ToString(); Error.httpcode = 500; return Error; } } </code></pre> <p>is this possible and a good thing to do? or should i just extend all return classes with my error class, even though i will return much info with allot of null values. i would like to send as little data as possible and if my function fails i'll just send back the error.</p> <p>UPDATE</p> <p>sorry for not giving enough inforamtion about my situation this is a function that i want to use in a webservice </p> <pre><code>[OperationContract] [WebGet( ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)] **** Function(); </code></pre> <p>so i dont think i can just throw an exception. i would like to return a class of articles if all is well so i dont have to convert my data to JSON but if something goes wrong i would like to send http code 500 Internal Server Error to the client. i have not yet read all answers but i think i'll have to include my error class in all my other return classes so the client can now when something went wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload