dennisgorelik: 2020-06-13 in my home office (Default)
2021-02-23 12:12:39 - Bought 200 ABNB $183.7
Observed ABNB growth up to ~$206

2021-02-24 - Observed ABNB decline down to ~$180
Promised to myself to sell ABNB at ~$206

2021-02-25 - Made a lucky mistake of not selling ABNB at ~$206

2021-02-25 14:12:25 - SOLD -2 ABNB $210.40
Unfortunately, I confused selling option contracts (which I could sell only 2 on top of 200 ABNB shares) with selling underlying ABNB shares (which I had 200).

Now I realized the mistake, but ABNB is only at ~$204 now (in the afterhours).

I guess I should reevaluate what to do with the remaining 198 of ABNB on the following Monday...
dennisgorelik: 2020-06-13 in my home office (Default)
Couple or years ago we tried to reuse exception handling code and created this method:
public static void ExecuteEmailCrashSuppressWebException(Action tryAction, Action reportAction)
{
	var tl = new TimeLog();
	try
	{
		tryAction();
	}
	catch (WebException) { return; }
	catch (Exception ex)
	{
		string displayName = tryAction.GetDisplayName();
		string message = CookMessage(displayName, reportAction, tl, ex);
		string subject = $"Win crash: {displayName}()";
		Log.ToFile(message, displayName + ".log");
		EmailToDevelopers.EmailTextIfSubjectWasNotSentRecently(subject, message);
	}
}

The idea was that if we know that a method may crash then we would just pass that method as a "tryAction" parameter.
Then ExecuteEmailCrashSuppressWebException() will swallow web exceptions, and will notify us (developers) about all other exceptions.

We wanted to avoid repeating try-catch boilerplate code by reusing ExecuteEmailCrashSuppressWebException().

That attempt [to reuse try-catch] failed miserably. Every tryAction method needed its own custom exception handling:
- In some cases we needed to swallow WebException, but in other cases we wanted to log it.
- In some cases we wanted to write to one "{tryAction}.log" file, but in other cases we wanted to write to differently named log file, or not to write to log file at all.
- Log message content was quite different for different tryAction methods.

Eventually we deleted ExecuteEmailCrashSuppressWebException() and wrapped every individual method that needed custom exception handling - by its own try-catch block of code.

My conclusion is:
Try-catch block should wrap only direct method calls.
Almost never try-catch should wrap Action/delegate invocation (such as "tryAction()").
The reason why wrapping delegate invocation with try-catch does not work is that "catch" implementation is very custom for every individual method.
Merging all these custom implementation into a single "catch" block produces unmaintainable mess.
dennisgorelik: 2020-06-13 in my home office (Default)
From "Committing code often" discussion:
It is ok to make mistakes, especially in the first "rapid-fire" version of the code.
There is no shame in it.

Even more: if you are not making any mistakes while coding - that means you are way too careful and are working much slower than you can.
(That does not mean, of course, that you should intentionally do mistakes. Just take greater risks in order to improve speed of programming/coding until you start getting occasional mistakes).

Profile

dennisgorelik: 2020-06-13 in my home office (Default)
Dennis Gorelik

June 2025

S M T W T F S
1234 567
891011 12 13 14
15161718192021
22232425262728
2930     

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 7th, 2025 05:53 pm
Powered by Dreamwidth Studios