Note that there are some explanatory texts on larger screens.

plurals
  1. POUnhandled Exception by a "throw new..", what's best practice? It's already handled
    primarykey
    data
    text
    <p>I try to put a exception logic which a part of a system can fall back to on unexpected behaviors. </p> <p>The work should be done of a new class that inherits <code>Exception</code> object and extend the functionality with a new "exit" which consist of a error-signal to the user and a logging routine.</p> <p>I may need to understand the use of <code>throw</code> better, but I though I could make it fairly transparent by i.e. this:</p> <pre><code>public SomeObject GetVersion(byte p) { switch ((SomeObject)p) { case Version.SomeType1: ... break; case Version.SomeType2: ... break; default: throw new UnexpectedQueryException(this.someOtherObject, errorCode); } return (SomeObject)p; } </code></pre> <p>I think you can see what I'm trying to do here. </p> <p>I try to throw when the application can't serve the request. The throw are meant to put the execution through the exception (which generates a adequate error code to caller). This example is a error of type "I know you gived me a 9 but only 1-8 is allowed here)", which errorCode sends further to the <code>UnexpectedQueryException(...)</code>. </p> <p>Unfortunately the application take the throw as unhandled and closes my Thread and application won't operate until restart. Beside this scenario i'm also use this throw in catch statements.</p> <p>In my eyes, this is Very handled.<br></p> <p>What best practice here? <br> I want the exception handling to be a "fall back" to activate on different scenarios (like above) so I always have an easy way to communicate an error back to the user (which mean I can send very exact info about where the exception is).</p> <p>Also i, Of Course, want the application to continue working. </p> <p>A part of code from the Exception logic,<br></p> <pre><code>public class UnexpectedQueryException: CommunicationException { public UnexpectedQueryException(SomeObject object, ErrorCode errorCode) : base("UnexpectedQueryException", object, errorCode) { ......... } } </code></pre> <p>Which, in turn, inherits the base Exception object, </p> <pre><code>public class CommunicationException : Exception { ..some fields.. public CommunicationException(string Message, SomeObject object, ErrorCode errorcode) { ..... } public CommunicationException() : base("CommunicationException") { } } </code></pre>
    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.
    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