Skip to content

Commit

Permalink
added configuration for stack trace writting
Browse files Browse the repository at this point in the history
  • Loading branch information
JMayrbaeurl committed Mar 10, 2017
1 parent aff5a1d commit fc925b3
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,26 @@
public final class IotHubSendTask implements Runnable
{
protected final IotHubTransport transport;

/**
* If true, full stack trace will be written to console on exception thrown by transport message sending
*/
private boolean verboseErrorMessaging = false;

public IotHubSendTask(IotHubTransport transport)
{
// Codes_SRS_IOTHUBSENDTASK_11_001: [The constructor shall save the transport.]
this.transport = transport;

if (this.transport == null)
throw new IllegalArgumentException("Value for parameter 'transport' must not be null");
}

public IotHubSendTask(IotHubTransport transport, boolean verboseErrMessaging)
{
this(transport);

this.verboseErrorMessaging = verboseErrMessaging;
}

public void run()
Expand All @@ -28,12 +43,20 @@ public void run()
}
// Codes_SRS_IOTHUBSENDTASK_11_005: [The function shall not crash because of an IOException thrown by the transport.]
// Codes_SRS_IOTHUBSENDTASK_11_008: [The function shall not crash because of any error or exception thrown by the transport.]
// JMayrbaeurl 2017-03-10: Bad idea to catch any Throwable here!!!
catch (Throwable e)
{
// JMayrbaeurl 2017-03-10: Should be replaced with real logging setup
System.out.println(e.toString() + ": " + e.getMessage());
for (StackTraceElement el : e.getStackTrace())

// Only output full stack trace on verbose Error messaging configuration
if (this.verboseErrorMessaging)
{
System.out.println(el);
for (StackTraceElement el : e.getStackTrace())
{
// JMayrbaeurl 2017-03-10: Should be replaced with real logging setup
System.out.println(el);
}
}
}
}
Expand Down

0 comments on commit fc925b3

Please sign in to comment.